Page 1 of 1

Theoreticaly, i thought this could work.....

Posted: Sun Nov 04, 2007 1:25 pm
by Monotoko
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


this is index.php, which should open main.txt and display it in a textbox, only thing is, its not displayin it in the textbox

Code: Select all

<html>
<body>
<textarea rows="10" cols="30">
<?
$ourFileName = "main.txt";
$fh = fopen($ourFileName, 'r') or die("Can't open file");
echo "$fh"
fclose($fh);
?>
</textarea>
</body>
</html>
main.txt has "hello" inside it, but instead its giving me "Resource id #3"

can anyone help me make it so it displays the contents of main.txt in the textarea?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Nov 04, 2007 1:44 pm
by alex.barylski

Code: Select all

<html> 
<body> 
<textarea rows="10" cols="30"> 
<? 
$ourFileName = "main.txt"; 
$fh = fopen($ourFileName, 'r') or die("Can't open file"); 
echo fread($fh, filesize());
fclose($fh); 
?> 
</textarea> 
</body> 
</html>
Notice the additional fread

Posted: Sun Nov 04, 2007 1:49 pm
by s.dot
A simple

Code: Select all

echo file_get_contents($filename);
would work.

Posted: Sun Nov 04, 2007 3:27 pm
by feyd
htmlspecialchars() will also be needed.

Posted: Sun Nov 04, 2007 3:59 pm
by Weirdan
and even simpler

Code: Select all

readfile($filename);
would work as well