Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UPLOAD_ERR_CANT_WRITE But other files are getting uploaded

Tags:

php

apache

ubuntu

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.

like image 491
chema Avatar asked Nov 13 '13 11:11

chema


3 Answers

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.

like image 108
chema Avatar answered Nov 08 '22 17:11

chema


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
like image 45
hwrod Avatar answered Nov 08 '22 17:11

hwrod


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.

like image 1
Manolo Avatar answered Nov 08 '22 17:11

Manolo