White_Lily Posted September 26, 2012 Share Posted September 26, 2012 Okay, so i need my CMS to determine whether a page exists or not without the user guessing, I looked up file_exists() on php.net, read what it does, and copied the code into mine and just changed the echos and $filename variable to what i needed them to be, the problem is it says completely the opposite of what its supposed to be. if i say: $filename = $GLOBALS["siteUrl"].$fetch["pageLink"]; if(file_exists($filename)){ echo "file exists"; }else{ echo "file not found"; } It says the file does NOT exist whereas if you go into the directory im pointing to, right there in front of you is the file. However, If i say: $filename = $GLOBALS["siteUrl"].$fetch["pageLink"]; if(!file_exists($filename)){ echo "file exists"; }else{ echo "file not found"; } It then says the DOES exist... Any ideas why its confusing the two? P.S: Ive echoed $filename and it shows the CORRECT file path, even including the file name. Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/ Share on other sites More sharing options...
Pikachu2000 Posted September 27, 2012 Share Posted September 27, 2012 Are you sure it's the correct path, from the root of the filesystem, or relative to the script you're running it in? In your second code block, you neglected to reverse the outputs. The way it reads, if the file doesn't exist, you'll get the "file exists" message. Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381225 Share on other sites More sharing options...
Barand Posted September 27, 2012 Share Posted September 27, 2012 You need to specify an absolute path on the server, not a URL Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381226 Share on other sites More sharing options...
White_Lily Posted September 27, 2012 Author Share Posted September 27, 2012 (edited) $GLOBALS["siteUrl"]; is: http://localhost/ and according to php.net, that type of file path IS supported by file_exists() and yes, the file path is correct. Edited September 27, 2012 by White_Lily Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381227 Share on other sites More sharing options...
White_Lily Posted September 27, 2012 Author Share Posted September 27, 2012 My reason for putting !file_exists() on the success message was to prove that it says the doesn't exist, even though the file i want to prove exists is staring me in the face. Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381228 Share on other sites More sharing options...
Pikachu2000 Posted September 27, 2012 Share Posted September 27, 2012 Without specifics, it isn't possible to help you much more with this . . . Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381232 Share on other sites More sharing options...
White_Lily Posted September 27, 2012 Author Share Posted September 27, 2012 the file_exists() code: $filename = $GLOBALS["siteUrl"]."template/".$fetch["pageLink"]; if(file_exists($filename)){ echo "<option value='1' selected='selected'>Yes</option>"; }else{ echo "<option value='0' selected='selected'>No</option>"; } echo "</select>"; echo $filename; the echo $filename:: http://localhost/template/index.php the $GLOBALS["siteUrl"]; code: $GLOBALS["siteUrl"] = "http://".$_SERVER['HTTP_HOST']."/"; Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381233 Share on other sites More sharing options...
Pikachu2000 Posted September 27, 2012 Share Posted September 27, 2012 Are you using MAMP/WAMP/XAMPP/etc. with a non-standard port number that would need to be included? Is there a reason you aren't using a filesystem path, perhaps with $_SERVER['DOCUMENT_ROOT'] to do this? Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381236 Share on other sites More sharing options...
PFMaBiSmAd Posted September 27, 2012 Share Posted September 27, 2012 file_exists is intended to work using file system paths. It does work with some URL wrappers, but http isn't one of them. Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381239 Share on other sites More sharing options...
Pikachu2000 Posted September 27, 2012 Share Posted September 27, 2012 I was starting to think that, but couldn't find anything in the manual that explicitly stated one way or the other. Where did you manage to find it? Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381245 Share on other sites More sharing options...
PFMaBiSmAd Posted September 27, 2012 Share Posted September 27, 2012 The file_exists requires stat() functionality. Here's the list of the http supported functionality - http://php.net/manual/en/wrappers.http.php Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381247 Share on other sites More sharing options...
Pikachu2000 Posted September 27, 2012 Share Posted September 27, 2012 Excellent, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381250 Share on other sites More sharing options...
White_Lily Posted September 27, 2012 Author Share Posted September 27, 2012 Hey, sorry for not replying, fell asleep after staying up half the night with my kid lol. I will give these suggestions a go later and will post the results :-) Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381275 Share on other sites More sharing options...
White_Lily Posted September 27, 2012 Author Share Posted September 27, 2012 Okay, so ive just tried using $_SERVER["DOCUMENT_ROOT"]; and it works! thanks guys for all the help Quote Link to comment https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381411 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.