1

I'm a PHP n00b but followed the instructions as per this excellent tut:

PHP Tizag file upload tutorial

However, whilst this worked perfectly on my Mac (OSX 10.8) running the default built-in Apache, it fails and doesn't work on a CentOS 6 box. Looking through the Apache logs I get this:

failed to open stream: No such file or directory

The permissions have been set to 777 on the "uploads" folder which is in the root of /var/www/html (on the mac it's /Library/Webserver/Documents)

[Tue Apr 30 13:05:11 2013] [error] [client (My IP Address)] PHP Warning:  move_uploaded_file(uploads/Today notes.txt): failed to open stream: No such file or directory in /var/www/html/test/uploads3.php on line 8, referer: ht*p://serverip.myserver.com/test/form4.html

[Tue Apr 30 13:05:11 2013] [error] [client (my IP address)] PHP Warning:  move_uploaded_file(): Unable to move '/tmp/phpc8AGo8' to 'uploads/Today notes.txt' in /var/www/html/test/uploads3.php on line 8, referer: ht*p://serverip.myserver.com/test/form4.html

Am I missing some setting in PHP or Apache to enable this to work properly?

Many thanks in advance.

Philippe Boissonneault
  • 3,949
  • 3
  • 26
  • 33
BSUK
  • 692
  • 1
  • 12
  • 28
  • 3
    Can you show the PHP code used – fullybaked Apr 30 '13 at 12:26
  • If you have a problem with a Tizag tutorial, please contact Tizag for support. And yes, as long as you get errors, you are missing something. To find out what, read the error messages and try to understand them. – M8R-1jmw5r Apr 30 '13 at 12:31
  • Remember case sensitivity when passsing your file path, easy to forget that macs are case insensitive, where cent os will be case sensitive. – AlexP Apr 30 '13 at 12:41
  • One often runs into this error, and to quickly troubleshoot it, follow these steps : http://stackoverflow.com/a/36577021/2873507 – Vic Seedoubleyew Apr 12 '16 at 16:41

4 Answers4

1

According to your question the uploads folder is in /var/www/html, however going by the error message it is trying to upload into /var/www/html/test/uploads which doesn't exist

Either you need to fix the code to upload to the correct path, or you need to create an uploads directory in the test directory

fullybaked
  • 4,117
  • 1
  • 24
  • 37
  • Thanks, you were right here, although the problem runs deeper than this as it still isn't working via curl which is what I'm actually attempting. I'd moved things into the temp directory during troubleshooting. I may have to post a new question to avoid confusion. – BSUK Apr 30 '13 at 17:32
  • 1
    There is now a troubleshooting checklist for this frequent error here : stackoverflow.com/a/36577021/2873507 – Vic Seedoubleyew Apr 12 '16 at 16:41
0

Please consult the documentation of your operating system. CentOS 6 has additional security configuration that might prevent PHP from accessing the tmp folder.

Allow that folder for access for Apache HTTPD (or change the temporary upload path to a folder Apache HTTPD is allowed access to by SELinux configuration). Also audit the SELinux log to find out what setting exactly prevents access to the directory.

E.g. if you're not running PHP as Apache Module, you might need to allow other processes (e.g. PHP (F)CGI binaries) protected file-system resources.

M8R-1jmw5r
  • 4,896
  • 2
  • 18
  • 26
0

Hope this will resolve your issue

first check if folder exist, if not create it as bellow

if(!is_dir('uploads/Today')){
   mkdir("uploads/Today", 0755);
}
Anand G
  • 3,130
  • 1
  • 22
  • 28
0

I know this is an old post, but like many people, nothing works that people suggest with this problem. However, I remembered a problem I had with something else years ago, and it ends up that it affects this situation also.

The problem was SELinux and you have to configure it to allow read/write: Centos 7 / Apache / PHP - mkdir(): Permission denied

Solution:

chcon -R -t httpd_sys_content_t /var/www/

chcon -R -t httpd_sys_content_rw_t /var/www/html/

If all else fails for you, try this solution.

Best of luck!

Fata1Err0r
  • 836
  • 1
  • 6
  • 14