【问题标题】:Trying to delete an image through php script试图通过php脚本删除图像
【发布时间】:2015-09-23 13:20:28
【问题描述】:

您好,我正在尝试制作一个从服务器中删除一些图像的脚本。 我阅读了每篇关于 unlink() 和主要权限/错误目录错误的帖子,link1link2,我尝试了所有找到的解决方案,但仍然找不到问题所在。

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

我总是将“exists”字符串作为输出,这意味着文件存在并且它不是目录错误。

当我使用时:

root@server ~ # locate 196040_DSCN2675.JPG

输出:

/var/www/vhosts/spiti360.gr/httpdocs/demo2/media/com_iproperty/pictures/196040_DSCN2675.JPG

图片没有删除。

我启用了错误显示,我接受了这个:

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

我在文件中同时使用chownchmod,我还在图片文件夹中使用chmod 777,因为我从here 读取但似乎没有任何改变。

drwxrwxrwx 2 root root 26333184 Jul  6 13:33 pictures

我什至尝试使用 system 和 rm 命令,但也没有用。 我知道这是一个权限错误,但是我从 stackoverflow 或 google 找到的任何解决方案都不起作用。

我错过了什么吗?

编辑: 我用过:chown -R root:www-data /var/www/vhosts/spiti360.gr/httpdocs/demo2/media/com_iproperty/pictures/

我将图片文件夹的用户组设置为 www-data

drwxrwxrwx 2 root www-data 26333184 Jul  6 14:15 pictures

但还是不行。

【问题讨论】:

  • 与 phpinfo();看看指令'disable_functions'。
  • 我是 root 并且 disable_function 没有价值。

标签: php apache permissions


【解决方案1】:
drwxrwxrwx 2 root root 26333184 Jul  6 13:33 pictures

您必须将用户和/或组设置为 www-data,我不记得两者是否都必须,否则 apache 将无权删除它。

【讨论】:

  • 只有组需要是www-data
  • 我用过这个:root@server ~ # sudo chgrp -R www-data /var/www/vhosts/spiti360.gr/httpdocs/demo2/media/com_iproperty/pictures/drwxrwxrwx 2 root www-data 26333184 Jul 6 13:33 pictures 还是不行。
  • 您也尝试编辑图像上的组?由于您尝试对图像进行 chmod 和 chown,因此图像也必须具有组。
  • 是的,我也使用 chgrp 来访问图像上的 www-data
  • 我能问一下你为什么要在删除图像之前执行 chmod 和 chown 吗?您是否尝试过直接取消链接?
猜你喜欢
  • 2021-11-28
  • 2015-08-13
  • 1970-01-01
  • 2011-10-21
  • 1970-01-01
  • 2013-07-22
  • 2013-02-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多