Ahhh, I see what's going on now. I had more time to read over the code, so
now I see what you are trying to do.
I'm not sure why it suddenly stopped working, but let's see if you actually
need it to work.
First of all, I take it that you have content which you want to write into a
file. Correct?
If so, why does it matter if the file you want to write it to has data
anyway? If you are just going to add data into it, isn't it ok that it is a
zerolength file?
Or is the problem that the file is _not_ actually zerolength, but PHP says
it's zerolength anyway?
Just try removing the !filesize() part, and then try executing the function.
But maybe I just don't understand what you are trying to write and why.
Could you be a little more specific what data is being saved in the file,
and what is in the file already?
--
Plutarck
Should be working on something...
...but forgot what it was.
"CC Zona" <[EMAIL PROTECTED]> wrote in message
9bebi3$133$[EMAIL PROTECTED]">news:9bebi3$133$[EMAIL PROTECTED]...
> > > 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]