(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ố
filename
Tê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;
}
filename
0
filename
1
filename
2
filename
3
filename
4 Robert Lerner ¶ ¶
6 năm trước
filename
5
filename
6
filename
7
filename
8
filename
9
filename
4 Ylearn ¶ ¶
17 năm trước
true
1
true
2
filename
4
Uramihsayibok, Gmail, com ¶ ¶
15 năm trước
true
4
true
5
true
6
filename
4 Ẩn danh ¶ ¶
9 năm trước
true
8
true
9
false
0
false
1 itadmin tại itmusicweb dot co dot uk ¶ ¶
19 năm trước
false
2
false
3
false
4
filename
4 Robert Lerner ¶ ¶
17 năm trước
false
6
false
7
filename
4Ẩn danh ¶ ¶
17 năm trước
false
9
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
filename
4 Ẩ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
filename
4 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
filename
4
Uramihsayibok, 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
filename
4Ngoài ra, một tệp sẽ được tải lên trong thư mục đã tải lên_files, vì vậy bạn cần đảm bảo rằng thư mục này tồn tại và có thể ghi bởi người dùng máy chủ web. Trong phần này, chúng tôi sẽ đi qua các phần chính của chỉ mục. Tệp PHP.uploaded_files directory, so you need to make sure that this folder exists and is writable by the web-server user. In this section, we'll go through the key parts of the index. php file.
Tệp () đọc một tệp vào một mảng. Mỗi phần tử mảng chứa một dòng từ tệp, với ký tự dòng mới vẫn được đính kèm.reads a file into an array. Each array element contains a line from the file, with the newline character still attached.
Nhận tiện ích mở rộng tệp bằng hàm pathinfo () trong PHP và xác thực định dạng tệp để kiểm tra xem người dùng có chọn tệp hình ảnh hay không.Tải lên hình ảnh lên máy chủ bằng hàm move_uploaded_file () trong PHP.Chèn tên tệp hình ảnh trong cơ sở dữ liệu MySQL bằng PHP.Trạng thái tải lên sẽ được hiển thị cho người dùng.
Tải lên đề cập đến việc truyền dữ liệu từ hệ thống máy tính này sang hệ thống khác thông qua các phương tiện của mạng.Các phương thức tải lên phổ biến bao gồm: tải lên qua các trình duyệt web, máy khách FTP] và thiết bị đầu cuối (SCP/SFTP).Tải lên có thể được sử dụng trong bối cảnh (có khả năng nhiều) máy khách gửi tệp đến máy chủ trung tâm.uploading via web browsers, FTP clients], and terminals (SCP/SFTP). Uploading can be used in the context of (potentially many) clients that send files to a central server.