想請問各位大大
PHP copy()能傳圖檔到指定的資料夾,但無法傳文件到指定的資料夾
是哪個環節有問題呢?
copy 是個很單純的動作
如果 copy 會失敗
我只想得到
1.檔名/路徑錯誤:找不到該檔案
2.權限問題:無法在該路徑讀/寫該檔案
如果上傳失敗,請在 move_uploaded_file 後面放一下 $FILES["file"]["error"];
看看吐給你什麼錯誤訊息 (下面是 0~8 分別代表的意思)
UPLOAD_ERR_INI_SIZE = Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
UPLOAD_ERR_FORM_SIZE = Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
UPLOAD_ERR_PARTIAL = Value: 3; The uploaded file was only partially uploaded.
UPLOAD_ERR_NO_FILE = Value: 4; No file was uploaded.
UPLOAD_ERR_NO_TMP_DIR = Value: 6; Missing a temporary folder. Introduced in PHP 5.0.3.
UPLOAD_ERR_CANT_WRITE = Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.
UPLOAD_ERR_EXTENSION = Value: 8; A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help.
如果是 copy 失敗,請參考下面程式碼的寫法,從 error_get_last() 取得錯誤訊息
<?php
if(!copy('...','...'))
{
$errors= error_get_last();
echo "COPY ERROR: ".$errors['type'];
echo "<br />\n".$errors['message'];
}
else
{
echo "File copied";
}
?>