SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 1999
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I am working on a download page where a PHP tracking program will keep record of the number of downloads for a particular file.

    Can you tell me the keys on how to redirect people to download a file while increments the number of downloads?

    I read somewhere that the URL is like this
    http://my.url.com/download.php3?=/files/xxx.zip

    but people click on this URL, the program will prompt the user of the location for which the file will be stored and a number will increment by one in the database.

    How do I do this? Also, I wanna to do this for 2 obvious reasons:
    1. To avoid people linking to my file
    2. To keep track of the number of downloads

    Thanks

  2. #2
    SitePoint Member
    Join Date
    Jun 2000
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just finished a script just like that I don't have mysql, so it creates a text file (or adds 1 to an existing file) depending on which file is after the .php?

    ----------------------------------*

    <?

    //define variables

    $logpath="/your/server/path/logs"; //NO TRAILING SLASH!

    $create=fopen("$logpath/$go.txt","a");
    fclose($create);

    $addtofile=fopen("$logpath/$go.txt","r");

    $thenum=fgets($addtofile, 255);

    $thenum2=$thenum+1;

    fclose($addtofile);

    $addtofileagain=fopen("$logpath/$go.txt","w");
    fputs("$addtofileagain", "$thenum2");
    fclose($addtofileagain);


    print("Added!");


    print("<body onLoad=parent.location=('http://$go');>");


    ?>

    -----------------*

    The only problem is if $go is something like http://www.somedomainhere.com/blah/etc/

    It will mess up because of the "/"...

    Anyone have any suggestions to fix that? Like parse out the / and reparse them back in?

    Thanks,

    -Matt

    ------------------
    -----
    ComicalPics.com

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 1999
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, it would seem most of the stuff you wrote in three deals with open file and close file. I think mySQL would be easier...

    Maybe I am more familiar with mySQL with PHP's file manipulation.

    My guess is that the key part is this line:
    print("<body onLoad=parent.location=('http://$go');>");

    This actually prompts users for downloads?

  4. #4
    SitePoint Member
    Join Date
    Jun 2000
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I could use mysql I would But as of now my provider doesn't have it. (yet)

    The whole key is the onload() javascript call, it will just fwd the user to $go, if its a .zip it will prompt to download, I just use it for going to domains like clickcount.php3?go=www.yahoo.com

    That will FWD you to yahoo.com

    -Matt

    ------------------
    -----
    ComicalPics.com

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 1999
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh Cool!

    Can you tell me what this does?
    Header("Location: $url");

  6. #6
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    usb,

    That adds a line to the HTTP headers that get sent with the current file. The line in question instructs the browser to load the specified URL instead. Seems like exactly what you need to me.


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  7. #7
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suggest you look in the PHP manual at the HTTP functions as you need to add some extra header fields to the Location header when you are using it to prompt people for a file download, one such header field places a suggest name to save the file as (If you don't use it then the url of the link the person clicked on will be in the filename box).

    Depending on the browser used it will mask the url, but seen as you are using it for file downloads then the URL will not appear in the address bar, however (Their is always something) if you linked it to a PDF file and the user had Adobe Acrobat installed and integrated with IE then IE would just simple open the file and it might (I say might because IE is funny sometimes) reveal the true URL of the file.

    ------------------
    Karl Austin
    KDA Web Services
    "Everyone has a photographic memory. Some just don't have film."

  8. #8
    SitePoint Enthusiast
    Join Date
    Dec 1999
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, this line is PHP server side?

    Will it hide the URL of my file?

    Header("Location: $url");

    Thanks!

  9. #9
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You can't rely on header() hiding the URL of the file you're redirecting to, no. There is no way you can do what you want using a simple redirect. Instead, you'll need to load the file in PHP and then send it to the browser as if it was the contents of the page. The code would be along these lines:

    // Identify this page as a binary file
    header("content-type: application/octet-stream");

    // Open the file
    $file = fopen("/path/to/file.zip","r");

    // Send the file
    fpassthru($file);


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

    [This message has been edited by kyank (edited August 07, 2000).]

  10. #10
    SitePoint Enthusiast
    Join Date
    Dec 1999
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote/font><HR>Originally posted by kyank:
    You can't rely on header() hiding the URL of the file you're redirecting to, no. There is no way you can do what you want using a simple redirect. Instead, you'll need to load the file in PHP and then send it to the browser as if it was the contents of the page. The code would be along these lines:

    // Identify this page as a binary file
    header("content-type: application/octet-stream");

    // Open the file
    $file = fopen("/path/to/file.zip","r");

    // Send the file
    fpassthru($file);


    <HR></BLOCKQUOTE>

    I have copied the same thing into my PHP3 program.

    &lt;?

    // Identify this page as a binary file
    header("content-type: application/octet-stream");

    // Open the file
    $file = fopen("/virtualhosts/usbworkshop.com/www/files/usbready.exe","r");

    // Send the file
    fpassthru($file);

    ?&gt;

    However, all I see is a page full of codes.

    How can I redirect people to download this file?



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
  •