Jump to content


Photo

File not working


  • Please log in to reply
2 replies to this topic

#1 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 14 July 2006 - 01:40 AM

<?php
	echo "<br><br><br>";
	if(file_exists("_private/count.txt"))
	{
		$file=@fopen("_private/count.txt","r+");
		$num=@fread($file,filesize("_private/count.txt"));
		@fwrite($file,$num+1);
		@fclose($file);
	}
	else
	{
		$file=@fopen("_private/count.txt","w+");
		$num=@fread($file,filesize("_private/count.txt"));
		@fwrite($file,$num+1);
		@fclose($file);
	}
	$num++;
	echo "There have been: $num views of this page";
?>
This code counts the number of views of my home page, but i now have 12131214121312151.21312141213E+151.21312141213E+311.21312141213E+1671.21312141213E+1671.21312141213E+1671.21312141213E+1671.21312141213E+1671.21312141213E+1671.21312141213E+1671.21312141213E+1671.21312141213E+168 as the number of views on my home page, what's wrong with my code?

Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

#2 venkir

venkir
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 14 July 2006 - 02:18 AM

filesize will give you the size of the file and not the value of the count stored int the file. Looks like you want to open the file, read the value stored in the file and then add to it, store it back. If so:

you will have to use fread and store the value in a variable and not use fliesize. Hope that helps!!!

-V

#3 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 14 July 2006 - 02:22 AM

You may want to use file_get_contents (http://www.php.net/file_get_contents) to read the value in the file.  You may also want to typecast your variable as an int.

http://us3.php.net/m...pes.typecasting




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users