Beasts Posted May 21, 2009 Share Posted May 21, 2009 hi, why is file_exists function acting weird? my code is : if (file_exists($filename)) { include($filename); } else { echo("error"); } the file does exist. but the error is given out. however, when i edit the code to be if(!file_exists($filename)) then it works the way i want? isnt that the oppsite? Quote Link to comment https://forums.phpfreaks.com/topic/159146-solved-file_exists-function/ Share on other sites More sharing options...
Maq Posted May 21, 2009 Share Posted May 21, 2009 however, when i edit the code to be if(!file_exists($filename)) then it works the way i want? isnt that the oppsite? No. Because, in the latter if statement, it's true that the file does NOT exist. So the include gets executed. Echo out your $filename and make sure it exists. Other than that your code looks fine. Quote Link to comment https://forums.phpfreaks.com/topic/159146-solved-file_exists-function/#findComment-839306 Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2009 Share Posted May 21, 2009 So, what is actually in $filename? I'll guess it is a URL - http://yourdomain.com/yourfile.php? Quote Link to comment https://forums.phpfreaks.com/topic/159146-solved-file_exists-function/#findComment-839311 Share on other sites More sharing options...
Beasts Posted May 21, 2009 Author Share Posted May 21, 2009 $filename = 'inc'.$_POST['page'].'.php'; anyway i think its solved although i posted my code here with organized, in my actual code i had it in a single line... when i organized the code its working ??? Quote Link to comment https://forums.phpfreaks.com/topic/159146-solved-file_exists-function/#findComment-839318 Share on other sites More sharing options...
Maq Posted May 21, 2009 Share Posted May 21, 2009 By organized, you mean properly formatted? You should always have your code properly formatted to easily detect problems and to maintain readable code. It only takes a moment. Quote Link to comment https://forums.phpfreaks.com/topic/159146-solved-file_exists-function/#findComment-839336 Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2009 Share Posted May 21, 2009 When you post code that is not the same as the code that is causing the problem, no one can help you. Quote Link to comment https://forums.phpfreaks.com/topic/159146-solved-file_exists-function/#findComment-839350 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.