Jump to content

File_Exists() Help


White_Lily

Recommended Posts

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.

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

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.

Link to comment
https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381225
Share on other sites

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']."/";

Link to comment
https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381233
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/268837-file_exists-help/#findComment-1381236
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.