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
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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.