SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Hybrid View

  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    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
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use the header() function to set the content-type to binary, and then use the readfile function to dump the file?

    // tracking..
    // do not send data to browser other wise header() will not work!
    header("Content-type: application/octet-stream");
    header( "Content-Disposition: attachment; filename=". $filename );
    header("Content-Transfer-Encoding: binary");
    readfile ("$filename");

  3. #3
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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....=(

    any idea?
    I DON'T want the option to specify the filename form within the php file..just a download idalog...?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  4. #4
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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).

    header("Content-type: application/octet-stream");
    header("Content-Transfer-Encoding: binary");
    readfile ("$filename");

    I think that should work fine

  5. #5
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm...so $filename would be the path to the file?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  6. #6
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:
    http://domain.com/folder/filename.exe
    i have a .htaccess file in /folder/

    which redirects all requests for filename.exe to:
    http://domain.com/download.php?link=filename.exe

    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~!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  7. #7
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>

  8. #8
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes...but cna the scirpt just take the count from the content deposition?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  9. #9
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...
    http://www.something.com/download.ph...ename=whatever

    On most server configurations, this should work.
    You then dont need the content disposition.

  10. #10
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm..and the same code? don't get what you mean. sorry
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  11. #11
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, if you use the same code.

    However, if you wanted to use
    http://www.something.com/download.php/filename.exe
    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];

    header("Content-type: application/octet-stream");
    header("Content-Transfer-Encoding: binary");
    readfile ("$filename");

    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>

  12. #12
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh..ICIC..Okay..

    Thanks..
    I'll think of what I can do....
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •