/    Sign up×
Community /Pin to ProfileBookmark

html code will not echo

I want to echo the contents of a .txt file to a php page so that it will be retrievable with an ajax function. The .txt file contains html code.

When I try to echo it the html code is not visible. How can I make it so that it can be shown by the browser.

PS. Im using file_get_contents() function to get file contents

Thanks in advance

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@eval_BadCode_Apr 23.2011 — A few notes:

Be careful about LFI (Local File Inclusion) and RFI (Remote File Inclusion), they are vulnerabilities that may let an attacker abuse a page which misuses file_get_contents() by not validating input (file location).

file_get_contents has 1 mandatory argument: the filename. This function will look in the immediate path for the file (the same directory as the executed script itself), unless the filename is an absolute path or some of the optional arguments are used.

The function returns a string.

So we need 2 files... actually we only need 1 file ?

yourPHPpage.php (live example: http://vircaelum.net/filegetcontents.php )
[code=php]
<?php

echo "<pre>", htmlentities(file_get_contents($_SERVER[SCRIPT_FILENAME])), "</pre>";

?>
[/code]


Worked for me...

Edit:

If you need help with the ajax part, you should post it in the "Javascript" forum.
×

Success!

Help @brian8765 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...