Laravel 5.2 干预图像 500 服务器错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34543732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.2 Intervention Image 500 Server Error
提问by Buglinjo
When I upload big images (4.2 MB) Intervention Image is throwing 500 Error...
当我上传大图像 (4.2 MB) 时,干预图像抛出 500 错误...
private function resizeImage($path, $imgName){
$sizes = getimagesize($path.$imgName);
if($sizes[0] > $sizes[1]){
ImageManagerStatic::make($path.$imgName)->fit(920,474)->insert(public_path() . "/uploads/applications/watermark.png",'bottom-right', 30, 30)->save($path."1_".$imgName);
}else{
ImageManagerStatic::make($path.$imgName)->heighten(474)->insert(public_path() . "/uploads/applications/watermark.png",'bottom-right', 30, 30)->save($path."1_".$imgName);
}
ImageManagerStatic::make($path.$imgName)->fit(440,226)->save($path."2_".$imgName);
File::delete($path.$imgName);
}
It works for smaller files. upload_max_filesize=10M
. When I comment this function it works :/
它适用于较小的文件。upload_max_filesize=10M
. 当我评论这个函数时,它起作用了:/
回答by Janaka R Rajapaksha
I had the same issue and increasing upload_max_filesize
were not enough.
I also increased memory_limit to 256M
and restarted the server. Then images were working with Intervention.
[Above changes are in php.ini file]
我有同样的问题,增加upload_max_filesize
还不够。我还增加memory_limit to 256M
并重新启动了服务器。然后图像与干预一起工作。【以上改动在php.ini文件中】
You may want to change upload_max_filesize
and memory_limit
according to file capacity you are using.
您可能要更改upload_max_filesize
,并memory_limit
根据文件容量所使用。
回答by Amit Gupta
Today I got the same issue in Laravel 5.5 while using Intervention Package for resizing images exactly at below code:
今天我在 Laravel 5.5 中遇到了同样的问题,同时使用干预包在下面的代码中完全调整图像大小:
Image::make($image_tmp)->save($image_path);
I don't have access to php.ini
file in server and server will take time for update so temporarily increased memory limit in function itselfin my Controller file like below:
我无权访问php.ini
服务器中的文件,服务器需要时间进行更新,因此在我的控制器文件中临时增加了函数本身的内存限制,如下所示:
In ImagesController.php file :-
在 ImagesController.php 文件中:-
public function addImage(Request $request){
// Temporarily increase memory limit to 256MB
ini_set('memory_limit','256M');
$extension = Input::file('image')->getClientOriginalExtension();
$fileName = rand(111,99999).'.'.$extension;
$image_path = 'images/'.$fileName;
$image_tmp = Input::file('image');
Image::make($image_tmp)->resize(1182, 1506)->save($image_path);
}
Hope it will help someone in future!
希望它会在将来对某人有所帮助!
回答by Arnaud Becquet
I had the same problem with Laravel 5.1 and Intervention Image library. In my case the issue came from the line Image::make($file) not the upload part.
我在 Laravel 5.1 和干预图像库中遇到了同样的问题。在我的情况下,问题来自 Image::make($file) 而不是上传部分。
I tried change the values of:
我尝试更改以下值:
- upload_max_filesize from 2M to 32M
- post_max_size from 2M to 32M
- upload_max_filesize 从 2M 到 32M
- post_max_size 从 2M 到 32M
Change nothing to the error I received.
对我收到的错误没有任何改变。
So I increase :
所以我增加:
- memory_limit to 256M
- 内存限制为 256M
It solved my problem. My hypothesis is that even if my image was about 6Mo, the image library needed a lot of memory to use it.
它解决了我的问题。我的假设是,即使我的图像大约是 6Mo,图像库也需要大量内存才能使用它。
回答by ssuhat
edit your php.ini:
编辑你的 php.ini:
upload_max_filesize = 40M
post_max_size = 40M
Maybe your post_max_size is under 4MB. And then restart the server.
也许你的 post_max_size 小于 4MB。然后重启服务器。