Re: fwrite not writing

From: Date: Mon, 16 Apr 2001 08:50:16 +0000
Subject: Re: fwrite not writing
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-48717@lists.php.net to get a copy of this message
> > This function suddenly stopped working, and I just can't seem to figure > out > > why. The only change made recently is that now the value of $force at > > calltime is sometimes true instead of being undefined or null. > > > > build_file("file_content","/path/to/file.inc","w",TRUE); > > > > function build_file($func_name,$filepath,$mode="w",$force=FALSE) > > { > > if($force or !file_exists($filepath) or !filesize($filepath)) //echo > > filesize($filepath) shows '0' > > { > > $content=$func_name(); //echo $content shows it's all there > > $fp=fopen($filepath,$mode); > > fwrite($fp,$content); > > rewind($fp); #temp test > > $read_back=fread($fp,100000); #temp test > > echo "<p>file content:</p>\n $read_back"; #temp test, displays > nothing > > fclose($fp); > > } > > } > > > > I've tried putting echoes and "or die('Error on __LINE__')" on > > every line, > > checked all the variable values, and found no answers from that. > > Everything shows exactly as it should be except that the content that > > echoes out so nicely *doesn't ever get written to the file*. The function > > runs to the end without error and the file's modification date is even > > updated. But the file remains empty. I'm probably missing something > > ridiculously obvious, but would someone please be kind enough to point out > > what it is? Thank you!! > What is this: > > !filesize($filepath) If filesize is zero (which it is <groan>), then do the rest (which it does--except the content it fetches never makes it into the file it writes to. How that can be, I dunno, but that apparently is what it's doing...) > Add this above your if loop: > > $filesize = filesize($filepath); > echo $filesize; Already tried echoing that and all the other values. Filesize is 0. > That might be causing your loop not to execute...if not, I'm not sure what's > wrong. I don't get it. It should work. It did work. Suddenly it's not. -- CC

« previous php.general (#48717) next »