如何上传大文件> 5 laravel 5 [英] How to upload large file > 5MB in laravel 5

查看:429
本文介绍了如何上传大文件> 5 laravel 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以知道如何上传大文件,超过5Mb的Laravel 5吗?我试图上传大约10MB的图片文件,但没有上传,我搜索了很多,并更新了以下设置: php.ini

  post_max_size = 500M; 
memory_limit = 500M;
upload_max_filesize = 500M

我已经重新启动Apache服务器,但仍然有问题。在 php.ini 或Laravel中是否有其他设置可以上传大文件?请帮忙。

编辑

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

if($ image&& $ image!=''){

$ extension = $ image-> getClientOriginalExtension();
$ imageName = $ this-> getUniqueName($ extension);
$ image-> move('gimages / profile_images /',$ imageName);
$ profile_image = $ imageName;
$ update_user_data ['image'] = $ profile_image;

$ / code>

非常感谢!

解决方案

如果你想上传大文件,你应该使用流。以下是执行此操作的代码:

  $ disk = Storage :: disk('s3'); 
$ disk-> put($ targetFile,fopen($ sourceFile,'r +'));

即使您上传了几个GB的文件,PHP也只需要几MB的RAM。 p>

来源: https://murze.be/2015/07/upload-large-files-to-s3-using-laravel-5/



<有关存储的使用和配置,请参阅Lrvl5文档:
https://laravel.com/docs /5.0/filesystem

May I know how to upload large file, more than 5Mb in Laravel 5? I am trying to upload around 10MB image file but it is not uploading, I searched a lot and updated following settings in php.ini

post_max_size = 500M;
memory_limit = 500M;
upload_max_filesize = 500M

I have restarted Apache server but still having issue. Is there any other setting in php.ini or in Laravel to upload large files? Please help.

Edit

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

            if($image && $image != '') {

                $extension  = $image->getClientOriginalExtension();
                $imageName = $this->getUniqueName($extension);
                $image->move('gimages/profile_images/', $imageName);
                $profile_image = $imageName;
                $update_user_data['image'] = $profile_image;
            }

Thanks much!

解决方案

If you want to upload big files you should use streams. Here’s the code to do it:

$disk = Storage::disk('s3');
$disk->put($targetFile, fopen($sourceFile, 'r+'));

PHP will only require a few MB of RAM even if you upload a file of several GB.

Source: https://murze.be/2015/07/upload-large-files-to-s3-using-laravel-5/

See Lrvl5 doc for usage and config of Storage : https://laravel.com/docs/5.0/filesystem

这篇关于如何上传大文件&gt; 5 laravel 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆