Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php- chmod(): No such file or directory

I was trying to upload an image to a php server and from there send the image to parse.com using this documentation : https://parse.com/docs/rest#files

but the in parse , I can see only 0 sized images. I am thinking that the problem is with file permission

so I tried to change the file permission.

            $target_path = "uploads/";
            $img =rand().basename( $_FILES['image']['name']);
            $target_path=dirname(__FILE__)."/".$target_path.$img;
            print($target_path);
            chmod($target_path,0777);

but while executing this I am getting the following warning

Warning: chmod(): No such file or directory in /var/www/test/new.php on line 15

I can see the file in the uploads folder. and the owner of the file is www-data. any pointers

PS: Instead of absolute path I tried using relative paths also.

like image 615
Hrishi Avatar asked Oct 05 '22 04:10

Hrishi


1 Answers

You are targeting the script file and not the PATH by doing 'FILE'.

Use 'DIR' and verify if the folder exist is_dir() before attempting permission verification.

$target_path = "uploads/";
$img =rand().basename( $_FILES['image']['name']);
$target_path=dirname(__DIR__)."/".$target_path.$img;
print($target_path);
chmod($target_path,0777);
like image 143
Musk Avatar answered Oct 19 '22 11:10

Musk