UPLOAD_ERR_CANT_WRITE But other files are getting uploaded
Asked Answered
D

4

12

I am facing a quite weird behavior in my server.

I can upload any files smaller than 1MB without problem, but those that are bigger return me an error UPLOAD_ERR_CANT_WRITE == 7.

The tmp/ folder has permissions since I can upload other files.

The config on my PHP.INI seems to be fine, I did upload files larger than 1MB using phpmyadmin before and it worked.

PHP.INI

  • file_uploads On
  • post_max_size 200M
  • max_execution_time 30
  • memory_limit 128M
  • max_file_uploads 20
  • upload_max_filesize 200M
  • upload_tmp_dir /tmp

There's something I am missing? at my local machine works perfectly same config :S

I use ubuntu server 13.04 PHP 5.4.9 and Apache 2.2.22

Sure is the most stupid thing ever and I wasted 2 hours in this, I already have checked loads of docs at php.net but no luck. Any help is more than welcome.

Thanks!!!

UPDATE 10-01-2014: Still no luck I could not fix it.

Deprived answered 13/11, 2013 at 11:5 Comment(3)
the destination has writable permission ? It should be 775.Fierce
as said I can upload files smaller than 1mb no problem :SDeprived
Have faced same problem recently , very rare but hair pulling issue, thanks for adding itRabon
D
23

Thanks to all your answers I found the error.

The server is an Ubuntu installation done by OVH installer. What I was not aware is that they will create the partitions in such a poorly way:

  • Filesystem Size Used Avail Use% Mounted on
  • overflow 1.0M 136K 888K 14% /tmp
  • /dev/md2 1.8T 13G 1.7T 1% /home

So what I did is modify in php.ini the upload_tmp_dir to another folder with space...

Terrible I've wasted so much time, I never thought was actually an space issue, since in the HD I have 2TB!

Once more thanks and hope this may work to someone else.

Deprived answered 15/1, 2014 at 10:40 Comment(4)
This was the solution for me too. The disk on my AWS micro instance disk filled up. I cleared out a bunch of junk, but I was still seeing the error. I set upload_tmp_dir to /usr/tmp and everything started working again. I still don't know where the original tmp directory is though.Aerator
Mine, like chema's, was defaulting to /tmp, which on my AWS instance was also defined as a measely 1M "overflow" partition (whatever that means). This appears to be an unfortunate effect of combining PHP's default location for upload_tmp_dir with AWS's bizarre /tmp partition. Changing the php.ini to point to a larger drive did the trick. Thanks for solving this.Karlsruhe
Actually according to this link, this strange /tmp partition is a result of running out of space on your regular partition and like hwrod's answer all you have to do is unmount it again.Karlsruhe
I spent 3 days on it and your comment saved me. Thanks a lot!Medamedal
F
2

Delete or move all files from /tmp and unmount the device so it uses the normal partition for /tmp.

 mkdir /usr/tmp
 mv /tmp/* /usr/tmp
 sudo umount -l /tmp
 mv /usr/tmp/* /tmp
Floyfloyd answered 16/6, 2015 at 14:37 Comment(1)
this looks like a nice solution, didnt try though.Deprived
H
1

It is probably due to your memory_limit configuration. Try to replace with 256M. If it works you should review your code to minify memory usage.

If it is due to your permissions configuration you'll see with:

ls -la /yourUploadDirectory

You should see something like:

drwxr-xr-x 65 user group     4096 nov 13 09:47 .
drwxr-xr-x  3 user   group       4096 ago  7 18:09 ..

group of . directory (first line) should be www-data. If it's not do:

chown yourUser:www-data /yourUploadDirectory

Also drwxr-xr-x should be drwxrwxr-x. If it's not do:

chmod 0775 /yourUploadDirectory

Now you're done to upload.

Herbie answered 13/11, 2013 at 11:9 Comment(10)
Hello, thanks for prompt reply. I havent tried before the memory_limit I raised it to 512MB and still no luck. Permissions on upload folder are fine. I can upload other smaller files :s weird isn't?Deprived
@chema, is there any file size limitation at your host?? Could you try to use file_put_contents() to write a 1 MB txt file ???Fierce
@AllenChak I have a dedicated server. :S I guess I am missing something stupid. Funny thing just 2 weeks a go I managed to restore a mysql DB of more than 10MB from phpmyadmin and it worked. Also note that the PHP script finish correctly but returning the witting error, when obviously he can write :S desperate here. Thanks!Deprived
Also checkout your open_basedir php.ini option. It should be comment, or written the directories that Apache can access.Herbie
@ManoloSalsas open_basedir no value, but as I said before, apache can write there. I uploaded smaller files before with success. Just tried now and also worked :S but file bigger than 1 MB I get the message that he cant write...Deprived
Ok. Are you sure that you're changing the right file? Check: find /etc/* -name php.ini and diff file1 file2 to know if there are differences between them.Herbie
I think so since the insfo I am getting it from phpinfo(); function and reflects my changes.Deprived
Uhm... Are you sure that you have enough free space in the hard disk? Try df command.Herbie
Still couldnt fix this. I am able to pay someone to do it for me. Anyone in the room?Deprived
It,s maybe obvious, but have you restated your server after your php.ini changes? service apache2 restartHerbie
N
0

I have the same issue with aws amazon, I used an instance type t2.micro with 8G in the hard disk and the disk became saturated, I try to upload a file in laravel project but I got an error "UPLOAD_ERR_CANT_WRITE", I changed the volume to 256G and it's work.

Nonconformist answered 3/7 at 15:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.