Hrishi
Hrishi

Reputation: 1434

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.

Upvotes: 5

Views: 22333

Answers (1)

Musk
Musk

Reputation: 1477

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);

Upvotes: 6

Related Questions