Content · Programming · PHP

PHP is_uploaded_file() Function: Usage and Examples

Verifies that a path came from an HTTP POST upload.

1 views Published Oct 17, 2026 Updated Oct 17, 2026

is_uploaded_file() Function is one of the PHP operations used in filesystem and stream workflows. Verifies that a path came from an HTTP POST upload. The examples below show what it does and how to handle its result.

What Is is_uploaded_file() Function?


Verifies that a path came from an HTTP POST upload.

Its syntax is:

is_uploaded_file(string $filename)

The parameters are:

  • string $filename — The source or destination filesystem path.

Return value: The declared return type is bool. Use move_uploaded_file() for the final move and validate content and size as well.

Requirements: Requires a real HTTP POST multipart/form-data upload; a CLI-created file is not a PHP-uploaded temporary file.

Important: Use move_uploaded_file() for the final move and validate content and size as well.

Example 1: Basic Usage


The basic example focuses on the behavior of is_uploaded_file() Function: verifies that a path came from an HTTP POST upload. Inputs are defined locally or shown as application-controlled paths.

<?php

if (isset($_FILES["attachment"])) {
    $temporaryPath = $_FILES["attachment"]["tmp_name"];
    var_dump(is_uploaded_file($temporaryPath));
}

The displayed value, file content or return status depends on the input and surrounding environment. Results involving local paths, identifiers or generated files are not fixed values.

Example 2: A Different Use Case


This second example illustrates another input or execution condition for is_uploaded_file() Function. Notice the different checks, arguments, or output handling.

<?php

$upload = $_FILES["resume"] ?? null;
if ($upload !== null && $upload["error"] === UPLOAD_ERR_OK && is_uploaded_file($upload["tmp_name"])) { echo "Uploaded file accepted"; }

This variation matters because use move_uploaded_file() for the final move and validate content and size as well.

Practical Example: Using the Operation in an Application


The following example demonstrates how is_uploaded_file() Function fits into a more complete file or archive workflow, including inputs and appropriate checks.

<?php

$upload = $_FILES["document"] ?? null;
if ($upload !== null && $upload["error"] === UPLOAD_ERR_OK && is_uploaded_file($upload["tmp_name"])) { echo "PHP recognized a POST file upload"; }

The operation shown is an illustrative script. Adapt the filenames, required permissions, and error handling to your own controlled application environment before running it.

Important Behavior and Edge Cases


  • Function behavior: Verifies that a path came from an HTTP POST upload.
  • Limitation: Use move_uploaded_file() for the final move and validate content and size as well.
  • Availability: Requires a real HTTP POST multipart/form-data upload; a CLI-created file is not a PHP-uploaded temporary file.

Comparison With Related Functions


Function or MethodDifference
is_uploaded_file() FunctionVerifies that a path came from an HTTP POST upload.
move_uploaded_file()Moves a verified HTTP-upload file to a final destination rather than only checking its origin.

Use is_uploaded_file() Function for the specific behavior described above. The related operation, move_uploaded_file(), serves a different purpose; do not substitute it unless that different behavior is intended.

Common Beginner Mistakes


MistakeCorrect Approach
Assuming this operation has the same behavior on every file or environment.Use move_uploaded_file() for the final move and validate content and size as well. Check prerequisites and return values before using the result.
Treating move_uploaded_file() as an interchangeable replacement for is_uploaded_file() Function.Moves a verified HTTP-upload file to a final destination rather than only checking its origin.

Key Takeaways


  • Verifies that a path came from an HTTP POST upload.
  • Use move_uploaded_file() for the final move and validate content and size as well.
  • Related operation: move_uploaded_file() — Moves a verified HTTP-upload file to a final destination rather than only checking its origin.

is_uploaded_file() Function is useful when its specific behavior matches your application requirement. Keep paths controlled, check failures, and handle environment-dependent operations deliberately.

Share this resourceSend this page to someone who may find it useful.