Home >Backend Development >PHP Tutorial >The is_uploaded_file() function is a function in PHP

The is_uploaded_file() function is a function in PHP

WBOY
WBOYforward
2023-09-07 09:37:021077browse

The is_uploaded_file() function is a function in PHP

is_uploaded_file() function checks whether the file was uploaded via HTTP POST. This function returns TRUE if the file was uploaded via HTTP POST. Returns FALSE on failure.

Syntax

is_uploaded_file(file_path)

Parameters

  • file_path -Specify the file to be checked.

Returns

The is_uploaded_file() function will return TRUE if the file is uploaded via HTTP POST. Returns FALSE on failure.

Suppose we are uploading the file "new.txt" with the following content.

This is demo text!

Example

<?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>";
   }
?>

Output

File new.txt uploaded successfully!
Reading Contents of the file:
This is demo text!

Let us see another example with file “details.txt”.

Example

Live Demo

<?php
$file = "newdetailstxt";
if(is_uploaded_file($file)) {
   echo ("Uploaded via HTTP POST");
} else {
   echo ("Not uploaded via HTTP POST");
}
?>

Output

Not uploaded via HTTP POST!

The above is the detailed content of The is_uploaded_file() function is a function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete