Chuyên đề CSDL và WEB– Bài 9 : PHP và File, Session, Cookies, Mail
© 2009 Khoa CNTT - ĐHKHTN
V
V
í
í
d
d
ụ
ụ
Chuyên đề CSDL và WEB– Bài 9 : PHP và File, Session, Cookies, Mail
© 2009 Khoa CNTT - ĐHKHTN
3.
3.
Di
Di
chuy
chuy
ể
ể
n
n
t
t
ậ
ậ
p
p
tin
tin
t
t
ừ
ừ
th
th
ư
ư
m
m
ụ
ụ
c
c
t
t
ạ
ạ
m
m
sang
sang
th
th
ư
ư
m
m
ụ
ụ
c
c
upload
upload
move_uploaded_file (tmp_name, saved_name)
Chuyên đề CSDL và WEB– Bài 9 : PHP và File, Session, Cookies, Mail
© 2009 Khoa CNTT - ĐHKHTN
Ki
Ki
ể
ể
m tra l
m tra l
ỗ
ỗ
i,
i,
đ
đ
ị
ị
nh d
nh d
ạ
ạ
ng, k
ng, k
í
í
ch thư
ch thư
ớ
ớ
c File upload
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
Chuyên đề CSDL và WEB– Bài 9 : PHP và File, Session, Cookies, Mail
© 2009 Khoa CNTT - ĐHKHTN
M
M
ộ
ộ
t
t
s
s
ố
ố
l
l
ỗ
ỗ
i
i
khi
khi
upload file
upload file
Mã lỗi Hằng số Ý nghĩa
0 UPLOAD_ERR_OK There is no error
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
7 UPLOAD_ERR_CANT_WRITE Failed to write file to disk
Chuyên đề CSDL và WEB– Bài 9 : PHP và File, Session, Cookies, Mail
© 2009 Khoa CNTT - ĐHKHTN
V
V
ấ
ấ
n
n
đ
đ
ề
ề
v
v
ề
ề
quy
quy
ề
ề
n
n
truy
truy
c
c
ậ
ậ
p
p
File
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ụccầnthiết
• Không cấp quyền ghi cho thư mục
WebRoot