Skip to content Skip to sidebar Skip to footer

Warning: File Upload Error - Unable To Create A Temporary File In Unknown On Line 0

Am getting the following error everytime I try to upload a file . 'Warning: File upload error - unable to create a temporary file in Unknown on line 0' Here is my HTML form,

Solution 1:

In a terminal type :

chmod -R 777 /your/upload/folder

you can know the folder where your php uploads files by executing this code :

$tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
die($tmp_dir);

In my case I get /var/... so when I sett 777 permission I get no error.

Edit

Setting 777 to /var is dangerous so you have to set it only to the folder where php uploads the file (which you can get buy the code above).

Solution 2:

You should check your php.ini and look for the 'upload_tmp_dir' option. It is empty by default. After that, check the permission of your tmp dir. If you want to know what upload_tmp_dir your server is using, you can simply use this snippet of code

$tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
die($tmp_dir);

Finally in a terminal shell you can type : chmod -R 777 'your_tmp_upload_dir'

Solution 3:

I was getting the same error when uploading files from WordPress. I got this error in the apache error log file:

"PHP Warning: File upload error - unable to create a temporary file in Unknown".

I fixed the error by commenting out upload_tmp_dir in /etc/php.ini. The upload_tmp_dir was set to /tmp. I also set the date.timezone. After rebooting the server I was able to upload media files from WordPress.

It seems php did not have permissions to write to the /tmp folder.

Solution 4:

If you don't know what it is, it is SeLinux. It is enabled as default in certain distributions like CentOS.

Check if you have SELinux running:

sestatus

In the case you have SELinux enabled, fix your permissions with the chcon command.

This is just an example for nginx:

chcon -R -h -t httpd_sys_script_rw_t /usr/share/nginx/tmp
chown -R nginx:nginx /usr/share/nginx/tmp
chmod -R ug+rw /usr/share/nginx/tmp

tmp dir, upload dir in chroot need be set to /tmp not full path.

Solution 5:

Possibly it is /tmp directory problem. Check that /tmp has correct access privileges and enough space size.

Post a Comment for "Warning: File Upload Error - Unable To Create A Temporary File In Unknown On Line 0"