首頁 >後端開發 >php教程 >is_uploaded_file()函數是PHP中的一個函數

is_uploaded_file()函數是PHP中的一個函數

WBOY
WBOY轉載
2023-09-07 09:37:021056瀏覽

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

# 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刪除