MutantJohn Posted January 21, 2015 Share Posted January 21, 2015 So, I'm trying to read a file from a different filepath than the current working directory. I have some simple PHP like this : <?php $input_map = "readfile.php"; $map_contents = file_get_contents($input_map); echo $map_contents."<br />\n"; ?> And this'll work fine because it's in the same directory but if I try to set $input_map = "/home/...", the browser will return an empty string. This script will work from the command line though. So how do I get file_get_contents() to read from the server's file structure instead of just the working directory? Edit : For example, this will not work through the browser : <?php $input_map = "/home/..."; $map_contents = file_get_contents($input_map); echo $map_contents."<br />\n"; var_dump($map_contents); ?> Link to comment https://forums.phpfreaks.com/topic/294108-php-file_get_contents-works-from-command-line-but-not-through-apache-server/ Share on other sites More sharing options...
MutantJohn Posted January 21, 2015 Author Share Posted January 21, 2015 Lol I'm dumb. The file I was analyzing was an XML one so to get it to actually print, I needed to echo it through htmlspecialchars(). *sigh* I hate myself sometimes. Link to comment https://forums.phpfreaks.com/topic/294108-php-file_get_contents-works-from-command-line-but-not-through-apache-server/#findComment-1503667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.