NameSilo

Replace/update array if it exists (PHP)

Spaceship Spaceship
Watch

nigelwong

Established Member
Impact
3
Replace/update array if it exists (PHP) [FIXED]

Hi,

I currently have a php script which writes to a text file once a file is downloaded:
PHP:
fwrite($handle_download, "$file|$ip|$time|$day|$month|$year\n");

However i want it so that it UPDATES instead of writing it down again (or delete the old entry). Is there a way that if $file is going to be written to the text file again, that it look for all instances for $file and delete them? How would i do that?

I am doing this because i want to do an 'inactivity' script where it finds all instances in the script where $time exceeds a certain limit, and if it does it will delete it (therefore if there are older instances of the file, it will delete it even though it may still be active)

If anyone can help me out, it will be greatly appreciated.

Thanks

I have tried this in my script, but it doesnt work.

PHP:
			//Delete Previous Download Entry if it Exists
			$entry=file("$file_download");
			$ent=fopen("$file_download", "w");
			foreach($entry as $line2)
			{
			  $thisline = explode('|', $line2);
			  if ($thisline[0] == $file)
				fputs($ent,$line2);
			  else
			unset($thisline);
			}
			fclose($ent);

EDIT: I got it working, i accidently swapped the "unset($thisline)" and the other function around =P
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back