Hi I tried to search online but really could not find it.
So what is the difference between $_FILES['file']['name']
and $_FILES['file']['tmp_name']
, or what is the $_FILES['file']['tmp_name']
exactly?
According to http://php.net/manual/en/features.file-upload.post-method.php,
$_FILES['userfile']['name'] The original name of the file on the client machine.
$_FILES['userfile']['tmp_name'] The temporary filename of the file in which the uploaded file was stored on the server.
So what is the difference between the temporary filename and original filename?
Thank you
PHP $_FILES The global predefined variable $_FILES is an associative array containing items uploaded via HTTP POST method. Uploading a file requires HTTP POST method form with enctype attribute set to multipart/form-data.
Error Messages Explained ¶ The error code can be found in the error segment of the file array that is created during the file upload by PHP. In other words, the error might be found in $_FILES['userfile']['error'] .
The PHP global $_FILES contains all the information of file. By the help of $_FILES global, we can get file name, file type, file size, temp file name and errors associated with file.
when you send a file to a server-side script (php or asp or...), server will upload and move your file to a temporary directory of itself until the processing of the script file is done. then it will remove the file from that directory. so $_FILES['file']['tmp_name']
is the path (not name) of that temporary file
so lets examine/see this: since the processing of a php file especially on a virtual server like xampp is very fast so we can't see tmp file when it's created. so we use sleep()
function of php to see what is happening exactly, here we have a single page containing a very simple php code which is here and this is what happening:
<?php
if (isset($_POST['submit'])) {
sleep (4);
echo $_FILES['fileToUpload']['tmp_name'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<form action="" method="post" enctype="multipart/form-data">
Select image to upload:
<input onchange="uImage(event)" type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
note1: for php servers you can find your server temporary path in php.ini file. it's the value of upload_tmp_dir
in that file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With