Home >Backend Development >PHP Tutorial >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.
is_uploaded_file(file_path)
file_path -Specify the file to be checked.
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!
<?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!
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!