You are here: Re: Increment (++) question « PHP Programming Language « IT news, forums, messages
Re: Increment (++) question

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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация