Frage

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

War es hilfreich?

Lösung

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;

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top