Jump to content

Deleting Files


mcmuney

Recommended Posts

I'm trying to modify this script to remove files that end with %enlarged.jpg or %enlarged.gif or %enlarged.png, can someone help with the if statement, I've tried several things, of which, nothing is working:

 

<?

$path = 'mem_images/xyz/'; // path to the directory to read

if ($handle = opendir($path)) {

   while (false !== ($file = readdir($handle))) {

    if(strrchr($file, '.') == '.png' || strrchr($file, '.') == '.gif' || strrchr($file, '.') == '.jpg') {

        if(!is_dir($file)){



if($file){ 

echo $file." <<< No Match Found - File Deleted<br>" ;



//Uncomment the line below once you have made sure the Query works and presents you a list of images not found.  Just a precaution till you are sure its correct. 

unlink("$path".$file) ;

//unlink("$file") ;

}

}

}

}

}

   closedir($handle);
?>

Link to comment
https://forums.phpfreaks.com/topic/70829-deleting-files/
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.