在我的錯誤日誌中找到上述錯誤令人驚訝,因爲我認爲我已經完成了必要的工作捕獲錯誤在我的PHP腳本:PHP警告:POST內容 - n字節的長度超過了第0行中未知數的3145728字節的限制
if ($_FILES['image']['error'] == 0)
{
// go ahead to process the image file
}
else
{
// determine the error
switch($_FILES['image']['error'])
{
case "1":
$msg = "Uploaded file exceeds the upload_max_filesize directive in php.ini.";
break;
....
}
}
在我的php.ini腳本,相關設置:
memory_limit = 128M
post_max_size = 3M
upload_max_filesize = 500K
據我所知,3M相當於3145728個字節,這是什麼,正在觸發錯誤。如果文件大小大於500k但小於3M,則PHP腳本將能夠按照正常運行,按照case 1
發出$msg
中的錯誤消息。
當帖子大小超過post_max_size
但仍然在內存限制內時,如何捕獲此錯誤而不是讓腳本突然終止並顯示PHP警告?我看過類似的問題here,here和here,但找不到答案。
爲什麼不將函數包裝在'try..catch'塊中? – inhan 2012-07-31 11:34:05
'error_reporting(E_ALL&〜E_WARNING);'關閉PHP警告。 – fdomig 2012-07-31 11:39:27
@fdomig這應該是絕對的最後的手段。 – 2012-07-31 11:48:17