I'm currently mirroring files. However, I would like to track these files, yet not have the hassle of those horrible urls like track.php?file=filename.exe
or something. hence, the link to a file would be something like: http://domain.com/filename.exe
but I would then have a .htaccess file with a Redirect code to redirect all file requests of http://domain.com/filename.exe to http://domain.com/track.php?file=filename.exe
All this so far is alright.
I have a current code which uses header()
to read the file for the user to download. However, it increases my log file twice and thats not good..only once per click.
does anyone have any idea to a better way to do this? of offering the download form a php file so a download dialog box opens for the user to select a filename and location to download the file to? thanks
You could use the header() function to set the content-type to binary, and then use the readfile function to dump the file?
// do not send data to browser other wise header() will not work!
header( "Content-Disposition: attachment; filename=". $filename );
Hmm..but that will cause the downlaod dialog to open..then when the use selects to save the file...after waiting 2 seconds or so..it'll open the same dialog again..
and thus it'll result in double recoridngs....=(
I DON'T want the option to specify the filename form within the php file..just a download idalog...?
Sorry, that was so you could specify the filename in the download. Excluding the content disposition header should do the trick.
I can remember having this problem, but then I upgraded to the latest IE at the time and the problem went!
(the content disposition header is a valid part of http).
I think that should work fine :)
hmm...so $filename would be the path to the file?
hmm..but now, the problem is that when ever anyone wants to downlaod a file...the filename would be the name of the script...
cna't it be the filename of the file they wanna download?
cause..this is how the script works..
someone downlaods a file..say:
i have a .htaccess file in /folder/
which redirects all requests for filename.exe to:
download.php will then record the click and sned the file for the user to download. the user should not know that all these are taking place.
currently after the modification, the good news is that the clicks ain't recoridng twice...but the filename is hence download.php
can't i set it as filename.exe?
thanks for your help really~!
lol.. that is what the content disposition part is for ;)
and yes $filename must include the path to the file if it is not in the current directory.
<Edited by PeterW on 01-05-2001 at 08:51 AM>
Yes...but cna the scirpt just take the count from the content deposition?
The content disposition header is purely for the purpose of specifying the filename.
I just thought of one way you could get round the problem
call the script with...
On most server configurations, this should work.
You then dont need the content disposition.
Hmm..and the same code? don't get what you mean. sorry
Yes, if you use the same code.
However, if you wanted to use
You would need to extract the filename from the $REQUEST_URI
I would use a simple function like this for that.
$filename = $REQUEST_URI;
$filename = explode ("/", $filename);
$filename = $filename[count($filename) - 1];
Only problem with that is that all the downloads MUST be in the same directory.
btw; you will need to be running apache for this to work, I think. I know the sitepoint servers support the feature. E.g. http://www.sitepointforums.com/index...stfilename.exe
<Edited by PeterW on 01-06-2001 at 05:15 AM>
I'll think of what I can do....