Jump to content

what's wrong with streaming text?


Recommended Posts

Every time I try to read or write to a text file, I get a warning saying "(file).txt is not a valid stream source".  What's wrong?  I'm using fopen() and fwrite() commands.

 

Edit:  Here's the code.

<?php
$text = $_REQUEST["rp"];
$text = htmlspecialchars($text, ENT_QUOTES);
fopen("temp.txt","w+");
fwrite("temp.txt", $text);
rewind("temp.txt");
fopen("tde.txt", "a+");
fwrite("tde.txt", "<p class='p0'>");
while(! feof("temp.txt"))
{fwrite("tde.txt", fgets("temp.txt")."<br />");}
fwrite("tde.txt", "</p>");
fclose("temp.txt");
fclose("tde.txt");
?>

Link to comment
https://forums.phpfreaks.com/topic/109997-whats-wrong-with-streaming-text/
Share on other sites

For fopen(), you use the return value of fopen() rather than the name of the file for subsequent operations like reading, writing, closing:

 

<?php
$text = $_REQUEST["rp"];
$text = htmlspecialchars($text, ENT_QUOTES);

$temp_fp = fopen("temp.txt","w+") or die("Can't open temp.txt");
fwrite($temp_fp, $text);
rewind($temp_fp);

$tde_fp = fopen("tde.txt", "a+") or die("Can't open tde.txt");
fwrite($tde_fp, "<p class='p0'>");
while(! feof($temp_fp))
{fwrite($tde_fp, fgets($temp_fp)."<br />");}
fwrite($tde_fp, "</p>");
fclose($temp_fp);
fclose($tde_fp);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.