Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.