Xune Posted February 27, 2008 Share Posted February 27, 2008 Hello, today I come to you all with a request, I just need some sort of php file that will tell me how many times a file in my directory (or multiple ones), have been downloaded.If you help me, I would greatly appreciate this...please and thank you Link to comment Share on other sites More sharing options...
justsomeguy Posted February 27, 2008 Share Posted February 27, 2008 You will need a script that reads the filename or ID and redirects to the file after updating a database. It would be best to store entries for each downloadable file in a database which would contain an ID number, filename, and counter. You would have a PHP script that gets the ID to download, looks up the filename in the database, increments the counter, and redirects to the file. You wouldn't be able to count downloads if you link directly to the file to download. So the download link would look like this:<a href="download.php?id=10">Then the PHP script would do something like this: $id = intval($_GET['id']);$result = mysql_query("SELECT filename FROM files WHERE id={$id}");if ($row = mysql_fetch_assoc($result)){ mysql_query("UPDATE files SET counter = counter + 1 WHERE id={$id}"); header("Location: {$row['filename']}"); exit();}else echo "File not found"; Link to comment Share on other sites More sharing options...
Xune Posted February 27, 2008 Author Share Posted February 27, 2008 thanks...(sorry, I am kinda a bit of a newbie at PHP, trying to learn it though, so once again, thanks) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.