Php-chmod (): no such file or directory

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

but in the syntax I can only see 0 dimension images. I think the problem is with the file permission

so i tried to change the file resolution.

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

      

but when doing this I get 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 file is owned by www-data. any pointers

PS: Instead of an absolute path, I also tried to use relative paths.

+3


source to share


1 answer


You are targeting the script file, not the PATH by executing FILE .

Use " DIR " and check if the is_dir () folder exists before trying to check permissions.



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

      

+2


source







All Articles