Jump to content

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


Go to solution Solved by 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);
?>
Edited by MutantJohn
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.