Hi i can't figure out how to do this checked the FAQs and keyword searched no luck. The new data is submitted by a form "post". all it does is add 25 to the line[4] of the text file. thanks!
So what you want to do is to have your script receive user input and add 25 to whatever value is in line number 4 of a specific file?
If this is the case, then this should work:
[tt]$lines = file("<filename>" /* Read <filename> into an array, each line having it's own index */
$lines[4] = rtrim($lines[4]) + 25; /* Remove trailing newlines and add 25 to line 4 */
if (!$fp = fopen("<filename>", "w") /* Open <filename> for writing to write back the data */
die("Unable to open <filename>"
foreach ($lines as $line) /* Loop over each line */
{
fwrite($fp, $line); /* Write the line to the file */
}
fclose($fp);[/tt] //Daniel
Oh, and I forgot to mention this.
If you use the above code, you can have race conditions and memory problems.
The race condition would occur when two users access the file at the same time and two processes opens and writes to the file simultaneously. This would most likely corrupt the file.
With memory problems, I mean that if you have a large file, when the whole file gets read into memory (in the array), your server may run out of memory. //Daniel
Hi that script works ok but i am having one more problem
I am using a form to post, and it is passing a variable to the php specifying which file to put the data in. But
the script wont work; it works when i just script in the variable but it wont work when the form send the variable
thanks
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.