CHUYÊN ĐỀ CSDL VÀ LẬP TRÌNH ỨNG DỤNG WEB 1- P8: Giáo trình cơ sở dữ liệu và thiết kế Website cho người mới bắt đầu. Rất cần thiết cho các bạn mới học làm Website. Bạn sẽ nắm được nhựng diều căn bản đến nâng cao khi đọc xong cuốn sách này.
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