How to upload large file > 5mb in laravel?

by giovanny.lueilwitz , in category: PHP Frameworks , 8 months ago

How to upload large file > 5mb in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by darion , 8 months ago

@giovanny.lueilwitz 

In Laravel, you can upload large files by increasing the maximum file size limit and adjusting your server settings. Here's how you can do it:

  1. Update php.ini: Locate your php.ini file and modify the following settings: upload_max_filesize = 20M (or more depending on your requirements) post_max_size = 20M (or more)
  2. Update .htaccess file (if using Apache): If you are using Apache, you may need to modify the .htaccess file in your Laravel project's public directory. Add or modify the following line: php_value upload_max_filesize 20M
  3. Modify Laravel configuration: Open the config/upload.php file and update the max_file_size value to your desired limit. For example: 'max_file_size' => 20 (20MB)
  4. Update your form: Make sure the form which accepts the file has the enctype attribute set to "multipart/form-data". For example:
  5. Handle the file upload in your controller: In your Laravel controller, you can handle file uploads using the store() method of the IlluminateHttpRequest object. For example: public function upload(Request $request) { $path = $request->file('file')->store('uploads'); // Process or save the file as required }


With these steps, you should be able to upload large files (> 5MB) in Laravel. Remember to adjust the file size limits based on your specific requirements.