I have been trying for a couple of hours to use file_get_contents on a local file on the server. This works fine with external websites and text files as a local file on the server:
Both of these work fine
file_get_contents($text_file);
file_get_contents($website_url);
When I try and get a PHP file its a different story, What gets returned is an empty string the same length as the file content length so:
file_get_contents($php_file);
when var_dump() return is (string) 99 “”
I’m wondering if it is a secuirty thing within apache.
Any ideas any1
EDIT: Hmmmm. (I should read more carefully - the caffiene is starting to kick in)
The PHP tags as HTML tags idea is a good possibilty too.
Definately don’t forget to look at view-source!
You weren’t viewing the contents of the PHP file as HTML were you? The PHP tag(s) will be interpreted as HTML tags which is why you wouldn’t see any text on the page.
Try doing view-source in your browser, or send along a plain text content type before echoing the file contents (header(‘Content-Type:text/plain;charset=utf-8’);).
The results varied so I’m guessing it has something to do with security - i.e. a known local file vs. a suspected remote file - the local isn’t parsed but the remote is.