
is_uploaded_file() 函数检查文件是否是通过 HTTP POST 上传的。如果文件是通过 HTTP POST 上传的,则该函数返回 TRUE。失败时返回 FALSE。
is_uploaded_file(file_path)
file_path -指定要检查的文件。
如果文件是通过 HTTP POST 上传的,is_uploaded_file() 函数将返回 TRUE。失败时返回 FALSE。
假设我们正在上传包含以下内容的文件“new.txt”。
立即学习“PHP免费学习笔记(深入)”;
This is demo text!
<?php
// checking for file is uploaded via HTTP POST
if (is_uploaded_file($_FILES['userfile'][‘new.txt'])) {
echo "File ". $_FILES['userfile'][‘new.txt'] ." uploaded successfully!</p><p>";
// displaying contents of the uploaded file
echo "Reading Contents of the file:</p><p>";
readfile($_FILES['userfile'][‘new.txt']);
} else {
echo "File ". $_FILES['userfile'][‘new.txt'] ." failed in uploading! File upload attack could be the reason!</p><p>";
}
?>File new.txt uploaded successfully! Reading Contents of the file: This is demo text!
Let us see another example with file “details.txt”.
Live Demo
<?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!
以上就是is_uploaded_file()函数是PHP中的一个函数的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号