- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
is_uploaded_file() function in PHP
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!
"; // displaying contents of the uploaded file echo "Reading Contents of the file:
"; readfile($_FILES['userfile'][‘new.txt']); } else { echo "File ". $_FILES['userfile'][‘new.txt'] ." failed in uploading! File upload attack could be the reason!
"; } ?>
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!
Advertisements