ICE NoteBook
2009年7月14日 星期二
PHP - 檔案上傳$_FILES error錯誤說明
使用PHP上傳檔案是非常方便的,相信用過ASP的人都有同感吧
但是無法上傳時就會需要取得錯誤資訊,我們可以使用以下方式印出上傳檔案的所有資訊
echo "
"; var_dump($_FILES); echo "
";
這時畫面上會秀出類似以下資訊
array(1) { ["upFile"]=> array(5) { ["name"]=> string(15) "elder200907.zip" ["type"]=> string(15) "application/zip" ["tmp_name"]=> string(14) "/tmp/phpr8syQq" ["error"]=> int(0) ["size"]=> int(1679389) } }
如果"error"不是0的時候,代表有問題,那麼我們就可以參考以下狀況
switch ( $_FILES [ $field ][ 'error' ]){ case 1: // 檔案大小超出了伺服器上傳限制 UPLOAD_ERR_INI_SIZE $this ->setError( "The file is too large (server)." ); break ; case 2: // 要上傳的檔案大小超出瀏覽器限制 UPLOAD_ERR_FORM_SIZE $this ->setError( "The file is too large (form)." ); break ; case 3: //檔案僅部分被上傳 UPLOAD_ERR_PARTIAL $this ->setError( "The file was only partially uploaded." ); break ; case 4: //沒有找到要上傳的檔案 UPLOAD_ERR_NO_FILE $this ->setError( "No file was uploaded." ); break ; case 5: //伺服器臨時檔案遺失 $this ->setError( "The servers temporary folder is missing." ); break ; case 6: //檔案寫入到站存資料夾錯誤 UPLOAD_ERR_NO_TMP_DIR $this ->setError( "Failed to write to the temporary folder." ); break ; case 7: //無法寫入硬碟 UPLOAD_ERR_CANT_WRITE $this ->setError( "Failed to write file to disk." ); break ; case 8: //UPLOAD_ERR_EXTENSION $this ->setError( "File upload stopped by extension." ); break ; } }
上面的錯誤資訊是網路搜尋來的,如有錯誤請盡快告訴我喔^^
沒有留言:
張貼留言
‹
›
首頁
查看網路版
沒有留言:
張貼留言