問題描述
當用戶在我的網站上上傳圖片時,我收到此錯誤.
錯誤消息是PHP 致命錯誤:/home 中的內存不足(已分配 80740352)(試圖分配 12352 字節)......."如何使用 php.ini 解決此問題?
這是我當前上傳的 php.ini 設置
upload_max_filesize = 2000M ;post_max_size = 2000Mmax_file_uploads = 8
有什么想法我還需要添加什么來解決這個錯誤?
最佳 memory_limit
值取決于您對上傳文件的處理方式.您是使用 file_get_contents 還是 GD 庫將文件讀入內存?在這種情況下,將 memory_limit 增加到至少與 upload_max_filesize 相同,最好更大.
如果您使用 GD,請記住,GD 會將整個圖像保存在內存中未壓縮.這意味著它需要width * height * bit-depth
范圍內的內存,例如,1024*768*32 = 25 165 824 bits = 3 MB
用于截圖,或者對于 14 兆像素的圖像多達 55 MB.
某些操作可能需要創建圖像的副本,因此請考慮將 memory_limit 設置為將圖像保留在內存中所需的兩倍.如果不需要,請確保不要一次將所有圖像加載到內存中.處理完圖像后,您可以通過在句柄上調用 imagedestroy 來釋放 GD 使用的內存.>
I get this error when users are uploading images on my site.
error msg is "PHP Fatal error: Out of memory (allocated 80740352) (tried to allocate 12352 bytes) in /home......." How can I fix this using php.ini?
Here is my current upload php.ini settings
upload_max_filesize = 2000M ;
post_max_size = 2000M
max_file_uploads = 8
Any ideas what else I need to add to solve this error?
The optimal memory_limit
value depends on what you are doing with the uploaded files. Do you read the files into memory using file_get_contents or the GD library? In that case, increase memory_limit to at least the same as upload_max_filesize, preferably more.
If you are using GD, keep in mind that GD holds the entire image uncompressed in memory. This means that it takes memory in the range of width * height * bit-depth
, e.g., 1024*768*32 = 25 165 824 bits = 3 MB
for a screenshot, or as much as 55 MB for a 14 megapixel image.
Some operations may need to create a copy of the image, so consider setting memory_limit to the double of what you need to keep the image in memory. Also make sure to not load all images into memory at once if you don't have to. You can free the memory used by GD by calling imagedestroy on the handle when you are done working with the image.
這篇關于PHP 致命錯誤:內存不足(已分配 80740352)(嘗試分配 12352 字節)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!