[php] 檔案上傳
php檔案上傳的流程
表單→伺服器→暫存檔→檔案目錄
表單部份
FROM要有
enctype=”multipart/form-data” 屬性
//單檔 //多檔 之後使用$_FILES['UploadFile']['tmp_name'][0~n]$_FILES $_FILES['UploadFile']['tmp_name'] 暫存檔路徑和檔名 $_FILES['UploadFile']['name'] 上傳的原始檔名 $_FILES['UploadFile']['type'] MIME類型.如 "image/gif" $_FILES['UploadFile']['size'] 檔案大小 $_FILES['UploadFile']['error'] 錯誤代碼 UPLOAD_ERR_OK 上傳成功 UPLOAD_ERR_INI_SIZE 大於php.ini upload_max_filesize的設定 UPLOAD_ERR_FORM_SIZE 大於表單MAX_FILE_SIZE設定 UPLOAD_ERR_PARTIAL 只傳送部份資料 UPLOAD_ERR_NO_FILE 沒有上傳的檔案 把上傳的暫存檔放到upload/test.dat (如果已經有的話會覆蓋)
move_uploaded_file($_FILES['UploadFile']['tmp_name'], 'upload/test.dat'); if( $_FILES['UploadFile']['error'] == UPLOAD_ERROR_OK ){ if(move_uploaded_file($_FILES['UploadFile']['tmp_name'], 'upload/'.$_FILES['UploadFile']['name'])){ echo '上傳成功'; } }