Thomisback Posted March 8, 2008 Share Posted March 8, 2008 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 https://forums.phpfreaks.com/topic/95069-file_exists-if-else-echo/ Share on other sites More sharing options...
uniflare Posted March 8, 2008 Share Posted March 8, 2008 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 https://forums.phpfreaks.com/topic/95069-file_exists-if-else-echo/#findComment-486966 Share on other sites More sharing options...
PFMaBiSmAd Posted March 8, 2008 Share Posted March 8, 2008 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 https://forums.phpfreaks.com/topic/95069-file_exists-if-else-echo/#findComment-486967 Share on other sites More sharing options...
Thomisback Posted March 8, 2008 Author Share Posted March 8, 2008 Thanks again! I am going to try it in a second and I will let you know guys know my results Thanks, your help is very appreciated! Link to comment https://forums.phpfreaks.com/topic/95069-file_exists-if-else-echo/#findComment-486971 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.