Hi there,
I was just wondering how the following is usually handled. I have created a download page in php which takes 1 id query as to the file that is requested. This is mainly so I can display download information and also increment my download counter.
The only problem being there is nothing to stop the destination URL from being used to starte the download anyway. So what is normally done under this circumstance? I need to monitor downloads of all my files via 1 page, so would it be a matter of copying the desired file to a temporary place on the server and then letting the client download that one? Then I run into issues as to when to delete the temporary file.
Anyway, just wondered, thanks loads in advance for your input!
Nick.
Download interface
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
Check the referer to the page and this way you can ensure that the user came from your_page.php and not a foreign host. Then use header() to set the content type to whatever file type they are downloading and then echo the file data to the page. This will then make the user download the file - but will only work if they were sent to the download via your site.
the problem with http_referrer is that it is an optional header... if you want to make sure they are coming from somewhere else in the same domain, you could start a session on the previous pages.. and then test in download script that the session is active (meaning: they are coming from a page on your site)
-
firkinfedup
- Forum Newbie
- Posts: 19
- Joined: Sat Dec 04, 2004 7:25 am
aaaah
Hi again,
That's cool, I didn't realise I could pass the file data manually. Would this mean that any resume support would be lost? I'm presuming I literally open the file into a byte array and send byte for byte the file.
Nick.
That's cool, I didn't realise I could pass the file data manually. Would this mean that any resume support would be lost? I'm presuming I literally open the file into a byte array and send byte for byte the file.
Nick.
you mean something like this?
[php
if (isset($_GET['path']))
{
header('Content-length: ' . filesize($_GET['path']));
header('Content-type: application/octetstream');
header('Content-Disposition: attachment; filename=' . $_GET['path']);
readfile($_GET['path']);
}
probably with fopen, fseek, fread you can implement resume etc too..
[php
if (isset($_GET['path']))
{
header('Content-length: ' . filesize($_GET['path']));
header('Content-type: application/octetstream');
header('Content-Disposition: attachment; filename=' . $_GET['path']);
readfile($_GET['path']);
}
probably with fopen, fseek, fread you can implement resume etc too..
-
firkinfedup
- Forum Newbie
- Posts: 19
- Joined: Sat Dec 04, 2004 7:25 am