iamkarsoft's avatar

Upload Files from 3 different file fields

I'm trying to handle 1 image and 2 pdf uploads form a form. so I have 3 file input fields like this


 <input type="file" name="user_profile_picture" >

  <input type="file" name="cv" id="" >


  <input type="file" name="cover_letter"">
      

and in my controller, everything works when I'm handling the upload of one 1 file, when i try to upload all 3 at the same time. that's when i get a blank request. nothing gets uploaded


   #getting the image
    if ($request->hasFile('user_profile_picture')) :

      #deleting old picture
      $user_profile_picture = $updateUser->user_profile_picture;

      if (!empty($user_profile_picture) || $user_profile_picture !== null) :
        $path = public_path('img/user-profile-pictures/' . $user_profile_picture);
        File::delete($path);
      endif;

      # get the image

      $image = $request->file('user_profile_picture');

      #get the file extension
      $filename = time() . '.' . $image->getClientOriginalExtension();

      # save and move the file
      $path = public_path('img/user-profile-pictures/' . $filename);
      # make image and save into database
      Image::make($image)->resize(150, 150)->save($path);
      $updateUser->user_profile_picture = $filename;

    endif;


    if ($request->hasFile('cv')) :
      $file = request()->file('cv');
      $ext = $file->getClientOriginalExtension();
      $path = request()->file('cv')->storeAs('public/cvs', auth()->user()->name . '.' . $ext);
      $updateUser->cv = $path;
    endif;


    if ($request->hasFile('cover_letter')) :
      $file = request()->file('cover_letter');
      $ext = $file->getClientOriginalExtension();
      $path = request()->file('cover_letter')->storeAs('public/covers', auth()->user()->name . '.' . $ext);
      $updateUser->cover_letter = $path;
    endif;
0 likes
1 reply
Dunsti's avatar

Are the files really uploadad? Check your browsers-developer-tools, if there are any errors.

Most common errors with file-uploads are:

  • files are too big --> check upload_max_filesize, memory_limit and post_max_size in php.ini

  • files need to long to upload --> check max_execution_time and max_input_time in php.ini

also check the settings of your webserver - for example nginx see here: https://www.nginx.com/resources/wiki/modules/upload/

Please or to participate in this conversation.