
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
nt
tậ
ập
ptin
tin t
từ
ừth
thư
ưm
mụ
ục
ct
tạ
ạm
msang
sang th
thư
ưm
mụ
ục
cupload
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
ts
số
ốl
lỗ
ỗi
ikhi
khi upload file
upload file
Mã lỗi Hằng sốÝ nghĩa
0UPLOAD_ERR_OK There is no error
1UPLOAD_ERR_INI_SIZE The uploaded file exceeds the
upload_max_filesize directive in
php.ini
2UPLOAD_ERR_FORM_SIZE The uploaded file exceeds the
MAX_FILE_SIZE directive that
was specified in the HTML form
3UPLOAD_ERR_PARTIAL The uploaded file was only
partially uploaded
4UPLOAD_ERR_NO_FILE No file was uploaded
6UPLOAD_ERR_NO_TMP_DIR Missing a temporary folder
7UPLOAD_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
ntruy
truy c
cậ
ập
pFile
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ấpquyền ghi cho thưmục
WebRoot

