skip to Main Content

I have a php script with no erros (I tested it in other servers), the problem is, in this server I cannot upload images from php.

I add 755 to folder, php.ini file upload is on, max file size is 12mb.

I run this:

chown apache /var/www/html/img-img/
chmod 755 /var/www/html/img-img/

but also didn’t solve my problem.

my php also try to create a folder to upload images inside img-img (no success):

 $pasta = date("dmy");
 $pasta_dir2 = "img-img/$pasta";
 if(!file_exists($pasta_dir2)){
  mkdir($pasta_dir2, 0755);
 }

I have this warnings:

move_uploaded_file(img-img/14719222_886454304825512_8860750091242176512_n.jpg): failed to open stream: Permission denied in /var/www/html/teste.php on line 38, referer: http://example.com/teste2.php 
PHP Warning:  move_uploaded_file(): Unable to move '/tmp/phptZYSam' to 'img-img/14719222_886454304825512_8860750091242176512_n.jpg' in /var/www/html/teste.php on line 38, referer: http://example.com/teste2.php

any ideas how to solve this without break server security?

2

Answers


  1. Chosen as BEST ANSWER

    this solve my problem: I don't know what it does, but works... if anyone knows, please, answer this and let me know.

    sudo chcon -t httpd_sys_rw_content_t /var/www/html/img-img -R
    

  2. Check if img-img folder exist and try to set 744 permission to all the folders and subfolders of html using chmod -R 0755 /var/www/html/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search