Question

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

Was it helpful?

Solution

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;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top