Hello im trying to make a script that deletes some images from the server. I read every single post about unlink() and the major permissions / wrong directory errors , link1 , link2 and i tried every solution i found but still cant find whats wrong.
$baseDir=dirname(__DIR__).'/media/com_iproperty/pictures/';
$deleteImage=$prefix.'_'.$imgParts[0].'.'.$imgParts[$imgLen-1];
var_dump($deleteImage); //196040_DSCN2675.JPG
$deleteThumb=$prefix.'_'.$imgParts[0].'_thumb.'.$imgParts[$imgLen-1];
$user='root';
var_dump($baseDir); ///var/www/vhosts/spiti360.gr/httpdocs/demo2/media/com_iproperty/pictures/
$commandyo='rm '.$baseDir.$deleteImage;
if (file_exists($baseDir.$deleteImage)) {
echo "exists";
chown($baseDir.$deleteImage,$user);
chmod($baseDir.$deleteImage,0777);
//system($commandyo);
unlink($baseDir.$deleteImage);
}
die();
I always take as output the "exists" string, that means that the file exists and it isnt a directory error.
When i use :
root@server ~ # locate 196040_DSCN2675.JPG
Output:
/var/www/vhosts/spiti360.gr/httpdocs/demo2/media/com_iproperty/pictures/196040_DSCN2675.JPG
The image didnt deleted.
I enabled the error display and i take this:
Warning: chown(): Operation not permitted in /var/www/vhosts/spiti360.gr/httpdocs/demo2/custom_scripts/eAgentSingle.php on line 562
Warning: chmod(): Operation not permitted in /var/www/vhosts/spiti360.gr/httpdocs/demo2/custom_scripts/eAgentSingle.php on line 563
Im using both chown
and chmod
on file and i also chmod 777
on pictures folder as i read from here but nothing seems to change.
drwxrwxrwx 2 root root 26333184 Jul 6 13:33 pictures
I even tried to use system and rm command but didnt work also. I aknowledge that this is a permission error , but whatever solution i used found from stackoverflow or google wont work.
Do i miss something ?
EDIT:
I used : chown -R root:www-data /var/www/vhosts/spiti360.gr/httpdocs/demo2/media/com_iproperty/pictures/
and i set usergroup for pictures folder to www-data
drwxrwxrwx 2 root www-data 26333184 Jul 6 14:15 pictures
But still doesnt work.