Re: Problem: Writing into Files?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 02 Aug 2009 13:14:42 +0300, "Parham Doustdar" <parham90@xxxxxxxxx>
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)

--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux