What is the is_uploaded_file function in PHP?

Overview

is_uploaded_file is used to check whether a file is uploaded through HTTP POST or not. This ensures that a malicious user cannot run scripts through files and compromise the security of a system. The general syntax for the function is as follows:

is_uploaded_file(string $filename): bool

Parameter

The is_uploaded_file function has one compulsory parameter, which is the name of the file you wish to check.

Return value

The is_uploaded_file function returns TRUE if the file is uploaded through HTTP POST. Otherwise, it returns false.

Example

The following example will help you understand the is_uploaded_file function better. As shown, we check whether the file main.txt has been uploaded through HTTP POST. It returns false in this case as no such file exists.

<?php
$file = "main.txt";
if (is_uploaded_file($file))
echo ("file is uploaded through HTTP POST");
else
echo ("file is not uploaded through HTTP POST");
?>

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved