Home » Php » php – $_FILES["imagefile"]["name"] return name but $_FILES["imagefile"]["tmp_name"] return null value?

php – $_FILES["imagefile"]["name"] return name but $_FILES["imagefile"]["tmp_name"] return null value?

Posted by: admin February 25, 2020 Leave a comment

Questions:

In my case i was include enctype on myform like

<form id="product_add" name="product_add" accept-charset="utf-8" action="product_add_inter.php" method="post" enctype="multipart/form-data">

then my input type file is

<input name="imagefile" class="form-control" type="file"   />

Problem is in server side i need to upload my image to distination folder.I was tried to get file from form using

$_FILES["imagefile"]["name"]

its worked and returned name of my image. But when i get the file using temp_name it return null values.

$_FILES["imagefile"]["tmp_name"]

how can i solve this.

How to&Answers:

First, ensure that PHP is configured to allow file uploads.
In your “php.ini” file, search for the file_uploads directive, and set it to On:

file_uploads = On

Also did you check like that

echo '<pre>'; print_r($_FILES);echo '</pre>'; 

and see the result. Are you getting file array and tmp_name?
check your php.ini file for file upload settings.

php.ini setting

Change the upload_max_filesize=2M to 8M

; Maximum allowed size for uploaded files.
upload_max_filesize = 8M 

; Must be greater than or equal to upload_max_filesize
post_max_size = 8M 

Here is also solution
PHP file upload error tmp_name is empty

Answer:

You can use this code to see the upload error:

print_r($_FILES['imagefile]['error']);

The error code 6 means that there is no tmp directory. Go to your php.ini and post whats behind that variable:

upload_tmp_dir =

Answer:

I have Checked your Code and its absolutly working fine

<?php
echo $_FILES["imagefile"]["name"];
?>
<form id="product_add" name="product_add" accept-charset="utf-8" action="Check.php" method="post" enctype="multipart/form-data">
<input name="imagefile" class="form-control" type="file"   />
<input type="submit" value="SUBMIT" />
</form>

Please
Check If phpinfo(given below) whether “file_uploads” is ON and upload_max_filesize

<?php
echo phpinfo();
?>