pcw Posted March 11, 2009 Share Posted March 11, 2009 Hi, I am trying to read a file and display its contents in a textarea. This is what I have got: <?php include("../../addons.php"); function add_temp() { adminheader(); $filename = "admin_header.php"; $fp = fopen( $filename, "r" ) or die("Couldn't open $filename"); while ( ! feof( $fp ) ) { $line = fgets( $fp, 1024 ); } print <<<ADDTEMP <form action="../../admin.php" method="POST"> Template Name:<input type="text" name="temp_name"></br> Folder:<select name="temp_folder"> <option>admin</option> <option>common</option> <option>extras</option> <option>mail</option> <option>members</option> </select> <textarea name="template">$line</textarea> ADDTEMP; adminfooter(); } add_temp(); ?> But when I run the script, it shows the textarea with ?> in it, and thats it. How do I print all the contents of the file, in the textarea? Thanks Link to comment https://forums.phpfreaks.com/topic/149014-solved-read-file-and-print-result-in-textarea/ Share on other sites More sharing options...
MadTechie Posted March 11, 2009 Share Posted March 11, 2009 $line = fgets( $fp, 1024 ); is only getting the last line, you need to append to the last line.. try this change $line = fgets( $fp, 1024 ); to $line .= fgets( $fp, 1024 ); Link to comment https://forums.phpfreaks.com/topic/149014-solved-read-file-and-print-result-in-textarea/#findComment-782566 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.