Dump file contents

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

Dump file contents

Post by HiddenS3crets »

What is the easiest way to display the code inside a file located on a server, such as accessing the file contents of /var/www/html/page.php?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

I assume you want to display the php code pre-processed...

if so take a look at highlight_file()
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

Post by HiddenS3crets »

No, I don't need to highlight the file, just need to display the contents inside a textarea so they can be edited.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

ahh....then use file_get_contents()
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

Post by HiddenS3crets »

I've tried that one too, but I cannot access server files directly using that function. Instead I would need to access a file like this: http://www.domain.com/page.php

This code is all processed by the time file_get_contents() is called so I just have access to the HTML output. I need to access server files directly so I can view the PHP code as well.

Side note regarding highlight_file(): I cannot use it due to safe mode being on. To get around this I tried putting this at the beginning of my script:

Code: Select all

ini_set('safe_mode', 'Off');
I still get the warning that safe mode restrictions are in effect though. Why doesn't ini_set() just turn it off? :(
Last edited by HiddenS3crets on Sun Jul 16, 2006 6:52 pm, edited 1 time in total.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

fortunately the only way you can do that is to go through the file system. you can not access raw php code through the virtual system (and that's a GOOD thing). If the virtual path is the only method by which you can access the files, then I'm afraid you're not going to be able to make it work.
Post Reply