• 13
• 15
• 27
• 9
• 9

# [web] [SOLVED] [php] Unable to read source file, unless using highlight_file()

This topic is 3918 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

On my server, I'm trying to read a source file using PHP, and then outputting the source. However, I can't read the file unless I'm using hightlight_file(), and I want to be able to get a plain-text version of it. I've just looked through my PHP info, but nothing there seems to be set that would prevent me from reading the files. I can read other types, such as text files, but no php source. PHP 5.2.1, XAMPP, WinXP [Edited by - deadimp on June 26, 2007 8:38:08 AM]

##### Share on other sites
Strange. File functions, such as file_get_contents or fpassthru, should not care about what the opened file is. Are you using include or require ? If so, I would recommend you don't, as PHP is forced to read through these to search for interpretable PHP source (unless, of course, you actually need the PHP source in the file to be interpreted).

##### Share on other sites
I've been using the basic file I/O functions, such as file_get_contents, fopen, file() [with implode()], and a few others, but I'm unable to actually get into the file. I'm not using include() or require(), though.

The snippet o' code:
header("Content-type: text");if (!$file || is_dir($file)) die('Invalid');echo implode("",file(\$file));return;

This is placed in the overall script, not a function.

EDIT: Aw, dammit. I forgot to look in the source of the file. Turns up, it was reading the file correctly, but my Content-type header isn't correct, I guess, and Firefox's DOM is hiding the PHP tags from me.

EDIT: Had to change it to 'text/plain'.