Hello.

When trying to upload files: rar, pdf, exe - PHP returns error 7 UPLOAD_ERR_CANT_WRITE. At the same time txt, ppt, gif and others loads normally.

The problem occurs on the internal server under Ubuntu 14.04 + apache2, php 5.6

With a normal hoster :) everything works great.

Obviously there is a gap in knowledge and configuration of apache / php, but for now I do not see a solution to the problem. Colleagues, if there is an understanding which way to dig, please send.

Thank.

For example, the script is generally elementary:

index.php

<form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="filename" class="form-control"> <button type="submit">Отправить</button> </form> 

upload.php

 print_r($_FILES); 
  • Check if you can write to the directory where upload.php is located - L. Vadim
  • @ L.Vadim so if other files are loaded? - teran
  • @teran Error, about permishins - there can not be something else. - L. Vadim
  • check for different file sizes, and then see some extensions of the mod_security type - teran

2 answers 2

Judging by the error problem in saving files. Check the directories in which you are trying to save files.

 UPLOAD_ERR_CANT_WRITE Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0. 

Source: http://php.net/manual/en/features.file-upload.errors.php

UPD. Check whether the folder is available for writing is_writable .

It is also possible that you load too large files and they are not placed in the temporary folder / tmp or which one you have in php.ini. Try changing the upload_tmp_dir to the folder path in php.ini where you definitely have a lot of free space.

  • I agree, but how can you otdebezhit? And why does the error with writing a file to disk appear only for certain file types: rar, pdf, exe ... Perhaps there are some additional MIME libraries that need to be installed. Somewhere on the Internet they talked about: sudo apt-get install php-mime-type - but so far I have not received the desired result. - Surf
  • This is not a lot of things, added an answer, try it - Yaroslav Molchan
  • Yeah, I also thought that there was not enough space for temporary files, replaced: upload_tmp_dir = / tmp with upload_tmp_dir = / var / www / tmp for the time of debug chmod 777 / var / www / tmp. Other php.ini changes - slightly increased the values ​​post_max_size = 80M; upload_max_filesize = 80M; memory_limit = 512M; max_execution_time = 130; memory_limit = 256M; A positive result has not yet received. Alas. - Surf
  • As an option to find a small pdf or rar file up to 1MB for example and try to upload, if you don’t fill it up then I don’t even know how to help, something you are missing :) - Yaroslav Molchan
  • File size for tests ~ 1 mb. Files of similar size but in a different format are loaded. - Surf

The debug ini_get () and sys_get_temp_dir () discovered two problems. First of all, for some reason some file types were temporarily not placed in / tmp: rar, pdf, exe ... I fixed it by changing to / var / www / tmp

Secondly, no matter how php.ini rules still remained: post_max_size 8M upload_max_filesize 2M

In general, I do not understand the logic, but I was able to override the settings only for the virtual host / etc / apache2 / sites-available /

 php_admin_value upload_tmp_dir "/var/www/tmp" php_admin_value upload_max_filesize 256M php_admin_value post_max_size 256M 

через php.ini, init_set(), .htaccess the same could not be done.