Jump to content

PHP file_get_contents() works from command line but not through Apache server...


MutantJohn

Recommended Posts

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);
?>

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.