常見缺陷
對 MAX_FILE_SIZE
設定的值,不能大於 php.ini 檔案
設定中 upload_max_filesize
選項設定的值。其預設值為 2M 位元組。
如果記憶體限制設定被啟用,可能需要將 memory_limit 設定的更大些,請確認 memory_limit 的設定足夠的大。
如果 max_execution_time
設定的值太小,指令碼執行的時間可能會超過該設定。因此,也請保證
max_execution_time
足夠的大。
注意: max_execution_time 僅僅只影響指令碼本身執行的時間。任何其它花費在指令碼執行之外的時間,諸如用函式 system() 對系統的呼叫、sleep() 函式的使用、數據庫查詢、檔案上傳等,在計算指令碼執行的最大時間時都不包括在內。
max_input_time
以秒為單位設定了指令碼接收輸入的最大時間,包括檔案上傳。對於較大或多個檔案,或者使用者的網速較慢時,可能會超過預設的
60 秒
。
如果 post_max_size
設定的值太小,則較大的檔案會無法被上傳。因此,請保證
post_max_size
的值足夠的大。
The
max_file_uploads configuration
setting controls the maximum number of files that can uploaded in one
request. If more files are uploaded than the limit, then
$_FILES will stop processing files once the limit is
reached. For example, if
max_file_uploads is set to
10
, then $_FILES will never contain
more than 10 items.
不對正在操作的檔案進行驗證可能意味著使用者能夠訪問其它目錄下的敏感資訊。
鑑於檔案路徑的表示方法有很多種,我們無法確保用使用各種外語的檔名(尤其是包含空格的)能夠被正確的處理。
開發人員不應將普通的 input
輸入欄位和檔案上傳的欄位混用同一個表單變數(例如 input
名都用
foo[]
)。