I am trying to delete a file from folder in php here is my model function

function deleteFiles()
    {
        $file = "http://localhost/copycopy/img/uploaded/long.jpeg";
            if(is_file($file))
            {
                @unlink($file); // delete file
                echo $file.'file deleted';
            }
            else
            {
                echo "no file";
            } 
    }   

but I always see "no file" and file is never deleted, file is in folder,because the url in $file actually displays the file in browser help me

有帮助吗?

解决方案

instead of using web url

$file = "http://localhost/copycopy/img/uploaded/long.jpeg";

use local path to file:

$file = $pathToYourWebSite . "/copycopy/img/uploaded/long.jpeg";

be sure to set $pathToYourWebSite to real location of your website;

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top