首页 >后端开发 >php教程 >is_uploaded_file()函数是PHP中的一个函数

is_uploaded_file()函数是PHP中的一个函数

WBOY
WBOY转载
2023-09-07 09:37:021038浏览

is_uploaded_file()函数是PHP中的一个函数

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”。

This is demo text!

示例

<?php
   // checking for file is uploaded via HTTP POST
   if (is_uploaded_file($_FILES[&#39;userfile&#39;][&lsquo;new.txt&#39;])) {
      echo "File ". $_FILES[&#39;userfile&#39;][&lsquo;new.txt&#39;] ." uploaded successfully!</p><p>";
      // displaying contents of the uploaded file
      echo "Reading Contents of the file:</p><p>";
      readfile($_FILES[&#39;userfile&#39;][&lsquo;new.txt&#39;]);
   } else {
      echo "File ". $_FILES[&#39;userfile&#39;][&lsquo;new.txt&#39;] ." 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中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除