PHP Unlink Not working

前端 未结 7 1550
小鲜肉
小鲜肉 2021-01-11 15:34

I am trying to delete photo in php using unlink. I have used it earlier on other server but this time it is not working. I have used absolute path for a test but still does

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-11 16:10

    use filesystem path,
    first define path like this:

    define("WEB_ROOT",substr(dirname(__FILE__),0,strlen(dirname(__FILE__))-3));
    

    and check file is exist or not,if exist then unlink the file.

    $filename=WEB_ROOT."img1.jpg";
    if(file_exists($filename))
    {
    $img=unlink(WEB_ROOT."img1.jpg");
    }
    

提交回复
热议问题