|
Posted by Tim Roberts on 03/22/07 05:39
"Chris" <dippyv(nospam)@yahoo.com> wrote:
>
>I'm using the following code
>
><?php
>header("Cache-Control: no-cache, must-revalidate");
>header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
>error_reporting(0);
>$incrementfilename = $_GET['textfilename'];
>$handle = fopen($incrementfilename, 'w');
>$incrementcontents = file_get_contents($incrementfilename);
>$incrementcontents = $incrementcontents + 1;
>fwrite($handle,$incrementcontents);
>fclose($handle);
>chmod($incrementfilename,0777);
>?>
>
>The code works until I reach 9. While I am expecting 10, the file has 1.
>Any ideas?
This shouldn't work at all. By passing 'w' to fopen, you are saying
"Please truncate this file to zero length." The fact that
file_get_contents can still read it is an accident.
Your best bet is probably to move the "fopen" after the
"file_get_contents". Or, perhaps, use "r+" instead of "w" and use fread to
get the contents.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
[Back to original message]
|