Maryem's avatar

How to upload file PDF using laravel?

I have an application based on Laravel 5 with file upload functionality. 1. I try to insert images(jpeg,bmp,png) and files(Docx,xlsx) so Everything works fine except uploading of PDF files. 2. Need help on how to insert files (pdf) using laravel? I use laravel framework with Mysql

    public function rules()
    {
    return [
    'proposition' => 'required',];
    $filename = count($this->input('filename'));
    foreach(range(0, $filename) as $index) {
        $rules['filename.' . $index] = 
    'required|mimes:pdf,jpeg,bmp,png,doc,docx,csv,xlsx|max:20000';
    }
    return $rules;
    }



   public function store(PropositionRequest $request)
   {
    $proposition = new Proposition();
    $prop = Proposition::create($request->all());
    $prop->saveTags($request->get('tags'));
     foreach ($request->filename as $filename) {
     $filename = $filename->store('filename');
     PropositionFiles::create([
     'proposition_id' => $prop->num_proposition,
      'filename' => $filename
        ]);
       }
0 likes
3 replies
Maryem's avatar

@martinbean i correct my code and its work good now for all type of files (pdf, docx, jpg, png ....) but the only issue is when I upload files around 2MB everything works fine, but not when I upload 2+MB files error (FileNotFoundException in MimeTypeGuesser.php line 123: The file "" does not exist)

RamRaj's avatar

In the validation or rules you set maximum size of file is 2MB, so may be your pdf file will be more than 2MB.

Please or to participate in this conversation.