Jump to content

file_exists & if, else, echo


Thomisback

Recommended Posts

Hi, I am trying to make a php script which retrieves a variable via flash and checks if it exists and returns back a different variable. For some reason it always says the does not exist, even if it does.

My code:

[code]
<?
$usr=$_POST['usr'];
$filename = 'http://www.mydomain.com/$usr/test.txt';

if (file_exists($filename)) {
$info = "Already exists";
echo("&info=$info");
} else {
    $info = "Success!";
echo("&info=$info");
}

?>

Does anyone see what it wrong with the code?

 

Thank you very much![/code]

Link to comment
Share on other sites

use double quotes when inserting variables without concatenation:

 

$filename = 'http://www.mydomain.com/$usr/test.txt';

 

should be either:

$filename = "http://www.mydomain.com/$usr/test.txt";

or concatenate:

$filename = 'http://www.mydomain.com/'.$usr.'/test.txt';

 

 

hope this helps,

Link to comment
Share on other sites

In addition to what uniflare posted to get the $usr variable to work, the last time I checked, file_exists() does not work with http/https protocols.

 

If this is a local file, you need to use a file system path, not a URL, in the file_exists() function.

Link to comment
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.