Jump to content

[SOLVED] file_exists...


acctman

Recommended Posts

I'm having trouble getting the statement below to process. I'm not receiving an error. If i remove the if file_exists function the glob and array_map work fine. Should I just add a @unlink and make the code run without the if statement all the time regardless is the file is there or not?

 

$ifile = glob("/home/site/public_html/imgs/2005/04/2946/imgPub/imgTmb/200_*.jpg");
if(file_exists($ifile)) {
array_map('unlink', $ifile);
}

Link to comment
https://forums.phpfreaks.com/topic/162039-solved-file_exists/
Share on other sites

i just tested the code without the IF statement and it does not output an error if the file is no longer there. so thats perfect. i can run the code below with no problem

 

$ifile = glob("/home/site/public_html/imgs/2005/04/2946/imgPub/imgTmb/200_*.jpg");
array_map('unlink', $ifile);

Link to comment
https://forums.phpfreaks.com/topic/162039-solved-file_exists/#findComment-855013
Share on other sites

well glob will only return files that match the pattern, so it's not like it will return files that don't exist.  if no files are found, it returns and empty array. So when array_map walks through each returned result and unlinks the file, it's either not going to unlink anything because there are no elements in the array to walk through, or else it's going to unlink a file that exists.

Link to comment
https://forums.phpfreaks.com/topic/162039-solved-file_exists/#findComment-855028
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.