Re: Problem: Writing into Files?
| From: | Ollisso | Date: | Mon, 03 Aug 2009 08:34:56 +0000 |
| Subject: | Re: Problem: Writing into Files? | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296192@lists.php.net to get a copy of this message | ||
On Sun, 02 Aug 2009 13:14:42 +0300, "Parham Doustdar" <parham90@gmail.com>
wrote:
Now this one always sets the file to one for some reason. I'll reiterate just in case there's been a misunderstanding on my part: [code] $fp = fopen($f, "r+"); while (!flock($fp, LOCK_EX)) sleep(1); $count = fgets($fp,filesize($fp)); ftruncate($fp, 0); fwrite($fp, ($count+1)); flock($fp, LOCK_UN); fclose($fp); Thanks a lot again for your help.This will work: $f = 'file.txt'; $fp = fopen($f, "r+"); while (!flock($fp, LOCK_EX)) sleep(1); $count = intval(fread($fp,1024)); fseek($fp,0,SEEK_SET); ftruncate($fp, 0); fwrite($fp, ($count+1)); fclose($fp); echo $count; (first you should create file file.txt manually, only then it will work) --