The is_uploaded_file() function checks whether a file was uploaded via HTTP POST. The function returns TRUE if the file is uploaded via HTTP POST. It returns FALSE on failure.
Syntax
is_uploaded_file(file_path)
Parameters
file_path − Specify the file to be checked.
Return
The is_uploaded_file() function returns TRUE if the file is uploaded via HTTP POST. It returns FALSE on failure.
Let’s say we are uploading a 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['userfile'][‘new.txt'])) { echo "File ". $_FILES['userfile'][‘new.txt'] ." uploaded successfully!\n"; // displaying contents of the uploaded file echo "Reading Contents of the file:\n"; readfile($_FILES['userfile'][‘new.txt']); } else { echo "File ". $_FILES['userfile'][‘new.txt'] ." failed in uploading! File upload attack could be the reason!\n"; } ?>
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
<?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!