PHP » I/O » is_uploaded_file()

Syntax:
bool is_uploaded_file( string filename)
filename
The name of the file.

Checks if a file is an uploaded one.

Files can be uploaded by using the HTTP POST method. When uploaded, files get a temporary name and are placed in a temporary directory specified in the php.ini file. In older versions of PHP is_uploaded_file() was used to verify that a file is an uploaded file, for security reasons. Since move_uploaded_file() became available it is more commonly used, since uploaded files normally need moved from their temporary location.

Examples

Code:
<?php

if (!isset($_REQUEST["seenform"])) {
?>
      <form enctype="multipart/form-data" action="is_uploaded_file.php" method="post">
      Upload file: <input name="userfile" type="file">
      <input type="submit" value="Upload">
      <input type="hidden" name="seenform">
      </form>
<?php
} else {
      if (is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
         print "Uploaded file found";
         // do something with the file here
      } else {
         print "Not an uploaded file";
      }
}

?>
Output:
Uploaded file found
Explanation:

The first time the page is loaded, a form is shown where the user can upload a file. When the button is pressed, the file is posted back to the same page, where is_uploaded_file() is used to check for the file. However, move_uploaded_file() is the recommended function to use.

See Also: