I have a table in which I storing files uploaded by users and a php page which is showing all the files uploaded by a particular user. There is a download link when user clicks on that link I am passing the file id to my download.php
page then in download.php page I am retrieving file data using that id. I want to generate a random key each time a user click a download link for a particular file and using this key and file id I want to retrieve file data from database. How can I do it.
Create a second table where you store your random keys and link them to the files you want to have downloaded.
Example:
|-------|-------------------------|
| key | file |
|-------|-------------------------|
| jfdhj | /downloads/somefile.txt |
|-------|-------------------------|
Of course, you could use the ID of the file in the file
column, and join it. The reason to do this, is that you can create several keys for one file.
Also: why not just use the ID from the database?