duanpin2034 2014-07-04 00:02
浏览 201
已采纳

unlink不起作用...文件是可写的并且存在

I have an image sharing website and recently I've noticed I can't delete some of my images via script.

My file is writable and exist (so it's not a permission issue), but why can't I unlink it?

echo    $file = base_path('./files/images/2013/11/TubeCom_3313c73ab7924b1f36ee49ad0979a16ad490f9a2.jpg');
echo    is_writable($file) ? ' @is_writable ' : ' !!is_writable ';
echo    is_file($file)     ?   ' @is_file ' : ' !!is_file';
$res = unlink($file);
var_dump($res);

Here is the result:

    ./home/siteecom/domains/site.com/public_html/files/images/2013/11/TubeCom_3313c73ab7924b1f36ee49ad0979a16ad490f9a2.jpg 
    @is_writable @is_file bool(false) 

I've also tried relative path ... didn't work

  • 写回答

2条回答 默认 最新

  • duanjianxu4288 2014-07-04 01:13
    关注

    I recently run into an issue like this before. Firstly you'll need to turn on error reporting as unlink() will tell you exactly what's wrong:

    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    

    You'll want to make sure the directory that contains the file you want to delete is writable (please supply the chmod permissions for us to help furthur).

    You should look into using realpath() to get the absolute path to the file. (I don't think this is the issue as it doesn't throw a file not found error).


    Your problem is almost certainly related to incorrect permissions for the directory you're trying to delete in and also the script thats trying to delete said files.

    If you could supply those permissions of both with something like:

    echo "Directory = ".substr(sprintf('%o', fileperms(DIRECTORY)), -4) . "<br />";
    echo "PHP File = ".substr(sprintf('%o', fileperms(SCRIPT)), -4) . "<br />";
    

    We can try and help you further.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真