Hi Guys

I am currently working on an image upload script. i want to log user upload and record their ips.
I worked on a script(its works) but i am not sure if it will be 100% reliable.

Here is code that i though of

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$filename =$_FILES['image']['name']  // take note of the filename of the file the user is uploading
$date = date("d-m-y / H:i:s");
$insertlogs = $date . " - " . $ip . " - " . $filename . "<br />";
$fopen = fopen("ips.html", "a");
fwrite($fopen, $invoegen);
fclose($fopen);
?>

However i have some doubts on it
1.What will happens if 2 different users upload a file at the same time.I mean will script write ip properly
2.Also it will be an ever expanding html file, will it be better to create html file for specific dates
Show me an example
3.How resource intensive is this script.Will it slow my server much and cause high server loads.If yes what can i do to limit that?
Ultimately i would like to link this to a php form where i will just input the filename and it show out the record

  1. Likely it will. But if it gets heavier, a database is more likely, as it won't have the multi-user issue.

  2. Unsure what you mean by this. Please explain.

  3. A server can handle more than you think. You can always implement specific caching to speed things up.

  4. Storing IP is in itself not reliable. It is easy to spoof, and a person's IP is likely to change over time. If you are only interested in when a file was accessed, why don't you look at the server logs? Everything is already there.

i just spotted an error in case some of you want to use this code
Change:
fwrite($fopen, $invoegen);
To:
fwrite($fopen, $insertlogs);

Sorry guys , was a typing mistake:P

@pritaeas
2.By ever-expanding html file i mean that the script will keep writing to ips.html(thus its size will keep increasing)
I am not interested in using when the file was accessed but rather the ip of the users who upload image
This is because i want to control what user upload(that is in case someone upload child porn images , i can show his ip to authorities)
Legally i should record this information

If traffic is low it will not be an issue. I'd prefer using a database.

i though of that dude but i want to avoid mysql hassle , also sql cause loads on server as well
THere is a potential that traffic become high(like 500-1k image/day)
I am looking for a php solution that don't cause excessive server loads even when high traffic comes it

Any suggestions?

That's what databases are made for... At least you won't have concurrency issues.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.