Jump to content

help with unlink( .. )...!


powaz

Recommended Posts

PHP.net Manual

unlink — Deletes a file

 

If i understand you correctly you wanted to delete all of your pictures under a certain directory?

 

This will remove all files under the directory and additionally remove the directory if you so require

function SureRemoveDir($dir, $DeleteMe) {
    if(!$dh = @opendir($dir)) return;
    while (($obj = readdir($dh))) {
        if($obj=='.' || $obj=='..') continue;
        if (!@unlink($dir.'/'.$obj)) SureRemoveDir($dir.'/'.$obj, true);
    }
    if ($DeleteMe){
        closedir($dh);
        @rmdir($dir);
    }
}

//SureRemoveDir('pathtodirectory', false);
//false indicates that you do not want to delete the directory as well

 

If your after just 1 file?

 

Then the method you used should work.

Link to comment
https://forums.phpfreaks.com/topic/58958-help-with-unlink/#findComment-292557
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.