acctman Posted June 13, 2009 Share Posted June 13, 2009 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); } Quote Link to comment https://forums.phpfreaks.com/topic/162039-solved-file_exists/ Share on other sites More sharing options...
MadTechie Posted June 13, 2009 Share Posted June 13, 2009 $ifile = an array. so that file won't exist Quote Link to comment https://forums.phpfreaks.com/topic/162039-solved-file_exists/#findComment-855000 Share on other sites More sharing options...
waynew Posted June 13, 2009 Share Posted June 13, 2009 $ifile should be a string containing the path to the file: $ifile = "images/image.jpg"; Quote Link to comment https://forums.phpfreaks.com/topic/162039-solved-file_exists/#findComment-855011 Share on other sites More sharing options...
acctman Posted June 13, 2009 Author Share Posted June 13, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/162039-solved-file_exists/#findComment-855013 Share on other sites More sharing options...
.josh Posted June 13, 2009 Share Posted June 13, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/162039-solved-file_exists/#findComment-855028 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.