SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not just increasing the value of a table cell. It's one step further:

    The download counter should only spin if the link has really been clicked or the download has started. At the moment I'm having a redirect to another download.php3 page which counts the counter up by one.

    Another problem is that the download doesn't start. How do I automatically let a download begin when redirected to this page?

    TIA!

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Making a download begin is as simple as including a META refresh tag in the HEAD of the confirmation screen (generated by your counter increment script):

    Code:
    <META HTTP-EQUIV=refresh CONTENT="0;URL=thefile.zip">
    As for only incrementing the counter if the download actually happens, the solution there is to make the counter script actually send the requested file to the browser. Use a call to header() to tell the browser what MIME type to receive, then use readfile() to send the contents of the file to the browser.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Addict SniperUK's Avatar
    Join Date
    Jul 2000
    Location
    UK
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to look at the script here
    http://www136.l4.xodox.com/index2.html
    hope this helps!

  4. #4
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by kyank
    As for only incrementing the counter if the download actually happens, the solution there is to make the counter script actually send the requested file to the browser. Use a call to header() to tell the browser what MIME type to receive, then use readfile() to send the contents of the file to the browser.

    Sorry for this dump ques, but..... how can I do this? If possible can you provide me with some code?

    Thanks alot!

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    For example, to send "myimage.gif":
    Code:
    Header("Content-Type: image/gif");
    readfile("myimage.gif");
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  6. #6
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool! it works!

    How can I customize the name of this file? In my download manager it always displays the name of my php3 file.

    And the same with file size. It's always unknown over ftp...

    [Edited by DIMA on 09-07-2000 at 07:05 AM]

  7. #7
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The file size can be set with an HTTP header (I'll have to look it up when I get home if nobody else comes up with it before then). I've heard the file name can be too, but I've never had opportunity to try. I'll try to find an appropriate header for that, too.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  8. #8
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! I'll wait...

  9. #9
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Content-Type: application/zip
    Content-Disposition: attachment; filename=filename.zip
    Content-length: nbytes


  10. #10
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks!

    the name works correctly now.... but the file size is still unknown

    Code:
    header("Content-length: nbytes");
    Or do I have to specify this "nbytes" ? If yes then it would be very difficult for me to set all the sizes....
    Can't I automate this process?

    TIA

  11. #11
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can use the filesize (filename) which returns a file size (integer) in bytes...

    $fsize = filesize("foo.zip");

  12. #12
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did this and it's still unknown... the only thing which is different from yours is that it's not a filename but a whole URL.

    Code:
    $url = $row["url"];
    $size = filesize($url);
    	
    header("Content-Type: application/x-stuffit");
    header("Content-Disposition: attachment; filename=$title $version");
    header("Content-Length: $size");

  13. #13
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, it has to a filename usually including a path or in the same directory...

  14. #14
    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 definitely don't want to use a URL for your filename -- this slows things down tremendously, as PHP retrieves the file using an HTTP download (masquerading as a browser requesting the file from your Web server) rather than just opening it directly from your hard drive.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •