techdude Posted March 24, 2011 Share Posted March 24, 2011 Hi. I have php code that attempts to read a file into a string using get_file_contents(), but it claims the file does not exist. I do the same thing in another php file (same directory) and it works. Only difference is that the first file has the call in a function. File one: $email_template = "../email_templates/new_instructor.html"; echo file_exists($email_template); $message = file_get_contents($email_template);//get the email template File two: $email_template = "../email_templates/new_instructor.html"; echo file_exists($email_template); echo file_get_contents($email_file); plz help.' thanx Quote Link to comment https://forums.phpfreaks.com/topic/231559-get_file_contents-does-not-work-with-existing-local-files/ Share on other sites More sharing options...
techdude Posted March 24, 2011 Author Share Posted March 24, 2011 By the way, this one beats me. Quote Link to comment https://forums.phpfreaks.com/topic/231559-get_file_contents-does-not-work-with-existing-local-files/#findComment-1191579 Share on other sites More sharing options...
kenrbnsn Posted March 24, 2011 Share Posted March 24, 2011 In the second example, you're looking for a file contained in the variable $email_file which you haven't assigned a value to, so you get an error. Ken Quote Link to comment https://forums.phpfreaks.com/topic/231559-get_file_contents-does-not-work-with-existing-local-files/#findComment-1191604 Share on other sites More sharing options...
techdude Posted March 25, 2011 Author Share Posted March 25, 2011 Excuse me for the typo. The second one does have the value set. $email_template = "../email_templates/new_instructor.html"; echo file_exists($email_template); echo file_get_contents($email_template); Quote Link to comment https://forums.phpfreaks.com/topic/231559-get_file_contents-does-not-work-with-existing-local-files/#findComment-1192146 Share on other sites More sharing options...
PFMaBiSmAd Posted March 25, 2011 Share Posted March 25, 2011 Only difference is that the first file has the call in a function. ^^^ You would need to post actual code that demonstrates/reproduces the problem. Posting two partial snippets of code, taken out of context of where they work and where they don't, without even identifying which one is which, doesn't help. Quote Link to comment https://forums.phpfreaks.com/topic/231559-get_file_contents-does-not-work-with-existing-local-files/#findComment-1192154 Share on other sites More sharing options...
techdude Posted March 29, 2011 Author Share Posted March 29, 2011 The code was error_reporting(E_ALL); ini_set('display_errors', '1'); file_get_contents("Auth.php"); The include_dir contained the /usr/share/pear folder. Found the solution, it was blocked by an open_basedir path, but because it was an include without a path, it DID NOT PRODUCE THE USUAL ERROR THAT "Open basedir restriction was in effect". Kind of a wierd effect, but it worked to add that file to the open base dir. I wonder why it fails silently. -- techdude Quote Link to comment https://forums.phpfreaks.com/topic/231559-get_file_contents-does-not-work-with-existing-local-files/#findComment-1193812 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.