PHP中的is_uploaded_file()函数
is_uploaded_file()函数检查文件是否通过HTTPPOST上传。如果文件是通过HTTPPOST上传的,则该函数返回TRUE。失败时返回FALSE。
语法
is_uploaded_file(file_path)
参数
file_path-指定要检查的文件。
返回
如果通过HTTPPOST上传文件,则is_uploaded_file()函数返回TRUE。失败时返回FALSE。
假设我们要上传的文件“new.txt”包含以下内容。
This is demo text!
示例
<?php
//检查文件是否通过HTTPPOST上传
if (is_uploaded_file($_FILES['userfile'][‘new.txt'])) {
echo "File ". $_FILES['userfile'][‘new.txt'] ." uploaded successfully!\n";
//显示上传文件的内容
echo "Reading Contents of the file:\n";
readfile($_FILES['userfile'][‘new.txt']);
} else {
echo "File ". $_FILES['userfile'][‘new.txt'] ." failed in uploading! File upload attack could be the reason!\n";
}
?>输出结果
File new.txt uploaded successfully! Reading Contents of the file: This is demo text!
让我们看另一个文件“details.txt”的例子。
示例
<?php
$file = "newdetailstxt";
if(is_uploaded_file($file)) {
echo ("Uploaded via HTTP POST");
} else {
echo ("Not uploaded via HTTP POST");
}
?>输出结果
Not uploaded via HTTP POST!
热门推荐
10 男士送花祝福语大全简短
11 创业失败返乡祝福语简短
12 美丽晚霞祝福语简短句
13 给爸爸发财祝福语简短
14 除夕对同学简短祝福语
15 家庭英语祝福语短句简短
16 大厦动工祝福语简短精辟
17 宝宝周岁可乐祝福语简短
18 导师退休花束祝福语简短