playstat
asked on
24 hour expire url with random url creation for cloaked file downloads
hi there
Does anyone know of a good script for file downloads.
I have a file i want to include for my signups but need it to expire within 24 hours with a random url generator(or some other means to hide the actual file location)
Any suggesstions
best regards
Does anyone know of a good script for file downloads.
I have a file i want to include for my signups but need it to expire within 24 hours with a random url generator(or some other means to hide the actual file location)
Any suggesstions
best regards
Add a datetime field to your user database, called something like 'downloadexpires', then update it when they have signed up:
$downloadexpires = date('Y-m-d H:i:s', strtotime('now + 24 hours'));
mysql_query("UPDATE users SET downloadexpires = '$downloadexpires' WHERE id = '$user_id'");
Then when you want to check the download time (called from hernst42's code above):
function downloadIsValid($user_id) {
$result = mysql_query("SELECT id FROM users WHERE downloadexpires > NOW() AND id = '$user_id'");
return (mysql_num_rows($result) > 0);
}
Only other thing is that it's a good idea to add a content-length header, especially if you're downloading large files:
header('Content-length: '.filesize($absolutePathOf File));
Make sure that you do use the correct MIME type for the file you're downloading - there is no such type as 'application/force-downloa d', so don't use it.
For your unique URLs, generate them at the time you register the user, md5() is good for this. You might find that it's useful to map them back to a script parameter using mod_rewrite on Apache.
I don't think you'll find a download script as such, it's really a very loose association of several small parts, and everyone will want to do it differently
$downloadexpires = date('Y-m-d H:i:s', strtotime('now + 24 hours'));
mysql_query("UPDATE users SET downloadexpires = '$downloadexpires' WHERE id = '$user_id'");
Then when you want to check the download time (called from hernst42's code above):
function downloadIsValid($user_id) {
$result = mysql_query("SELECT id FROM users WHERE downloadexpires > NOW() AND id = '$user_id'");
return (mysql_num_rows($result) > 0);
}
Only other thing is that it's a good idea to add a content-length header, especially if you're downloading large files:
header('Content-length: '.filesize($absolutePathOf
Make sure that you do use the correct MIME type for the file you're downloading - there is no such type as 'application/force-downloa
For your unique URLs, generate them at the time you register the user, md5() is good for this. You might find that it's useful to map them back to a script parameter using mod_rewrite on Apache.
I don't think you'll find a download script as such, it's really a very loose association of several small parts, and everyone will want to do it differently
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the points :)
To output a file in PHP you can use the following:
if (downloadIsValid()) {
header("Content-type: $mimetype");
header("Content-Dispositio
readfile($absolutePathOfFi
} else {
echo "no longer able to download file";
}