Jump to content


Photo

Printing Contents of a File


  • Please log in to reply
1 reply to this topic

#1 nerd_energy

nerd_energy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 September 2006 - 12:13 AM

OS - XP, PHP 4, 5 Objective: To write the contents of about.txt to the web page.

I copied this from a PHP book and this is not working.  The book states that the function fpassthru will print the contents.  I also tried to replace this function with readfile function.  With both pieces of code, there was no error; just empty webpage
<?
$fh = fopen("about.txt" , "r");
if (!$fh)
{
die("Failed to open file <b>about.txt</b>.");
}
$s = fread($fh, 256);
fpassthru($s);
fclose($fh);
?>

Here is my third try with another PHP Programmers help.  We tried  to dump the contents into an array using function FILE.  However, the funny or not funny thing is in my editor FILE doesn't turn color to tell me it's a function.

<?php
$file = file($filename);
?>
<html>
<body>
<?php
foreach($file as $row){
echo $row;
}
?>
</body>
</html>

Is it possible to write to a web page?  I have tried other variations; even using echo. 
Thank you


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 07 September 2006 - 12:17 AM

See

http://www.php.net/readfile
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users