Flying Sagittarius Posted June 13, 2008 Share Posted June 13, 2008 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"); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted June 13, 2008 Share Posted June 13, 2008 Its likely you don't have permissions to access the file or the file doesn't exist. We can't reallt tell without seeing code. Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted June 13, 2008 Share Posted June 13, 2008 can you specify the error? i mean which file and lines and etc... Quote Link to comment Share on other sites More sharing options...
Flying Sagittarius Posted June 13, 2008 Author Share Posted June 13, 2008 Right now, it doesn't like these two lines. (It still says "no streaming text".) while(! feof("temp.txt")) {fwrite("tde.txt", fgets("temp.txt")."<br />");} Quote Link to comment Share on other sites More sharing options...
btherl Posted June 13, 2008 Share Posted June 13, 2008 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); ?> Quote Link to comment Share on other sites More sharing options...
Flying Sagittarius Posted June 13, 2008 Author Share Posted June 13, 2008 When opening a file, I have to assign it to a variable? Ok, thanks. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 You don't assign the filename to variable, you assign the file resource returned from fopen to a variable and use it in subsequent operations Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.