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
Release: 2023-09-07 09:38:02
forward
1075 people have browsed it

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)
Copy after login

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!
Copy after login

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

Output

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

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");
}
?>
Copy after login

Output

Not uploaded via HTTP POST!
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template