(Php 4> = 4.0.3, Php 5, Php 7, Php 8)
IS_UPLOADED_FILE - cho biết liệu tệp có được tải lên qua bài đăng HTTP không — Tells whether the file was uploaded via HTTP POST
Sự mô tả
is_uploaded_file (chuỗi $filename): bool(string $filename): bool
Loại séc này đặc biệt quan trọng nếu có bất kỳ cơ hội nào được thực hiện với các tệp được tải lên đều có thể tiết lộ nội dung của chúng cho người dùng hoặc thậm chí với người dùng khác trên cùng một hệ thống.
Để làm việc phù hợp, hàm is_uploaded_file () cần một đối số như $ _files ['userFile'] ['tmp_name'], - tên của tệp được tải lên trên máy của máy khách $ _files ['userFile'] ['name'] không làm việc.is_uploaded_file() needs an argument like $_FILES['userfile']['tmp_name'], - the name of the uploaded file on the client's machine $_FILES['userfile']['name'] does not work.
Thông số
filenameTên tệp đang được kiểm tra.
Trả về giá trị
Trả về true khi thành công hoặc false về thất bại.true on success or false on failure.
Ví dụ
Ví dụ #1 is_uploaded_file () ví dụis_uploaded_file() example
<?phpif (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
echo "Displaying contents\n";
readfile($_FILES['userfile']['tmp_name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}?>
Xem thêm
- Move_uploaded_file () - Di chuyển một tệp được tải lên đến một vị trí mới
- $_FILES
- Xem Xử lý tải lên tệp để biết ví dụ sử dụng đơn giản.
Thông tin tại Metaltoad Dot Net ¶
19 năm trước
As of PHP 4.2.0, rather than automatically assuming a failed file uploaded is a file attack, you can use the error code associated with the file upload to check and see why the upload failed. This error code is stored in the userfile array (ex: $HTTP_POST_FILES['userfile']['error']).
Here's an example of a switch:
if (is_uploaded_file($userfile)) {
//include code to copy tmp file to final location here...
}else{
switch($HTTP_POST_FILES['userfile']['error']){
case 0: //no error; possible file attack!
echo "There was a problem with your upload.";
break;
case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
echo "The file you are trying to upload is too big.";
break;
case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
echo "The file you are trying to upload is too big.";
break;
case 3: //uploaded file was only partially uploaded
echo "The file you are trying upload was only partially uploaded.";
break;
case 4: //no file was uploaded
echo "You must select an image for upload.";
break;
default: //a default error, just in case! :)
echo "There was a problem with your upload.";
break;
}
filename0
filename1
filename2
filename3
filename4Robert Lerner ¶ ¶
6 năm trước
filename5
filename6
filename7
filename8
filename9
filename4Ylearn ¶ ¶
17 năm trước
true1
true2
filename4Uramihsayibok, Gmail, com ¶ ¶
15 năm trước
true4
true5
true6
filename4Ẩn danh ¶ ¶
9 năm trước
true8
true9
false0
false1itadmin tại itmusicweb dot co dot uk ¶ ¶
19 năm trước
false2
false3
false4
filename4Robert Lerner ¶ ¶
17 năm trước
false6
false7
filename4Ẩn danh ¶ ¶
17 năm trước
false9
Uramihsayibok, Gmail, com ¶ ¶
15 năm trước
<?phpif (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
echo "Displaying contents\n";
readfile($_FILES['userfile']['tmp_name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}?>
0
<?phpif (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
echo "Displaying contents\n";
readfile($_FILES['userfile']['tmp_name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}?>
1
<?phpif (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
echo "Displaying contents\n";
readfile($_FILES['userfile']['tmp_name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}?>
2
Ẩn danh ¶ ¶
17 năm trước
<?phpif (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
echo "Displaying contents\n";
readfile($_FILES['userfile']['tmp_name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}?>
4
<?phpif (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
echo "Displaying contents\n";
readfile($_FILES['userfile']['tmp_name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}?>
5
<?phpif (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
echo "Displaying contents\n";
readfile($_FILES['userfile']['tmp_name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}?>
6
<?phpif (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
echo "Displaying contents\n";
readfile($_FILES['userfile']['tmp_name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}?>
7
Uramihsayibok, Gmail, com ¶ ¶
17 năm trước
<?phpif (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
echo "Displaying contents\n";
readfile($_FILES['userfile']['tmp_name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}?>
9
Ylearn ¶ ¶
17 năm trước
As of PHP 4.2.0, rather than automatically assuming a failed file uploaded is a file attack, you can use the error code associated with the file upload to check and see why the upload failed. This error code is stored in the userfile array (ex: $HTTP_POST_FILES['userfile']['error']). 0
As of PHP 4.2.0, rather than automatically assuming a failed file uploaded is a file attack, you can use the error code associated with the file upload to check and see why the upload failed. This error code is stored in the userfile array (ex: $HTTP_POST_FILES['userfile']['error']). 1
filename4Uramihsayibok, Gmail, com ¶ ¶
17 năm trước
As of PHP 4.2.0, rather than automatically assuming a failed file uploaded is a file attack, you can use the error code associated with the file upload to check and see why the upload failed. This error code is stored in the userfile array (ex: $HTTP_POST_FILES['userfile']['error']). 3
As of PHP 4.2.0, rather than automatically assuming a failed file uploaded is a file attack, you can use the error code associated with the file upload to check and see why the upload failed. This error code is stored in the userfile array (ex: $HTTP_POST_FILES['userfile']['error']). 4
filename4