I have a file that I'd like another script to access using file_get_contents
The file I'd like it to access is in the directory above it, so I'm using file_get_contents('../file.php?this=that')
However, it's returning No such file or directory
and I can't understand why. The file is there.
I'm assuming it has something to do with it being a local file rather than a remote. Any ideas or workarounds?
According to PHP.net the correct solution to reading files using file_get_contents function from the local server is using
// <= PHP 5
$file = file_get_contents('./people.txt', true);
// > PHP 5
$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);
Thought it might help instead of using workarounds!
file_get_contents('../file.php?this=that')
This will never work, unless you build a full URL with the entire http://....
syntax. PHP will see this as a request to get a file named file.php?this=that
one level above the current directory. It won't treat it as a relative URL and do an HTTP request, it'll use the local filesystem handler instead. You may very well have file.php
up there, but since the local file system has no concept of URLs or query parameters, it won't know to strip off the ?this=that
and just load file.php
. Hence your 'no such file error'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With