Di chuyển tập tin từ thư mục tạm sang thư mục upload move_uploaded_file tmp_name, saved_name... Một số lỗi khi upload file1 UPLOAD_ERR_INI_SIZE The uploaded file exceeds the upload_max
Trang 1Ví dụ
Trang 23 Di chuyển tập tin từ thư mục tạm sang thư mục upload
move_uploaded_file (tmp_name, saved_name)
Trang 3Kiểm tra lỗi, định dạng, kích thước File upload
Lưu ý :
– $_FILES["…"]["type"]
• "image/gif"
• "image/jpeg" Æ Firefox nhận đây là file jpeg
• "image/pjpeg" Æ IE nhận đây là file jpeg
– $_FILES["…"]["size"] : Kích thước file tính theo byte
– $_FILES["…"]["error"] : Mã lỗi khi upload File
• = 0 : Không có lỗi
• > 0 : Có lỗi
Trang 4Một số lỗi khi upload file
1 UPLOAD_ERR_INI_SIZE The uploaded file exceeds the
upload_max_filesize directive in php.ini
2 UPLOAD_ERR_FORM_SIZE The uploaded file exceeds the
MAX_FILE_SIZE directive that
was specified in the HTML form
3 UPLOAD_ERR_PARTIAL The uploaded file was only
partially uploaded
4 UPLOAD_ERR_NO_FILE No file was uploaded
6 UPLOAD_ERR_NO_TMP_DIR Missing a temporary folder
Trang 5Vấn đề về quyền truy cập File
PHP Warning:
move_uploaded_file(upload/14.jpg
) [function.move-uploaded-file]:
failed to open stream:
Permission denied in.
Account
IUSR _XXX
Lưu ý :
• Chỉ cấp quyền ghi cho thư mục cần thiết
WebRoot