SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    file size in force download

    I use following script to force download but how do I show file size of the downloadable file.

    <?php

    $file = base64_decode($file);
    header("Content-Description: File Transfer");
    header("Content-Type: application/force-download");
    header("Content-Disposition: attachment; filename=".basename($file));
    @readfile($file);

    ?>

  2. #2
    SitePoint Evangelist ClickHeRe's Avatar
    Join Date
    Mar 2005
    Location
    Ottawa, Canada
    Posts
    580
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Content-Length if I'm not mistaken

  3. #3
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You define the size of the file using the Content-Length header:

    PHP Code:
    header('Content-Length: 'filesize($file)); 
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  4. #4
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when i add the lines header('Content-Length: '. filesize($file)); . The file does'nt download.

    ____________________________________________________________

    <?php
    $file = base64_decode($file);
    header("Content-Description: File Transfer");
    header('Content-Length: '. filesize($file));
    header("Content-Type: application/force-download");
    header("Content-Disposition: attachment; filename=".basename($file));
    @readfile($file);
    ?>

  5. #5
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I'm not sure it'll work, but try using application/octet-stream instead of application/force-download.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  6. #6
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still not working.

    <?php

    $file = base64_decode($file);
    header("Content-Description: File Transfer");
    header('Content-Length: '. filesize($file));
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=".basename($file));
    @readfile($file);

    ?>

  7. #7
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Try removing the @ before readfile and see if you get an error message.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  8. #8
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No error but still not working saying 0 byets in 1 sec

  9. #9
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Does it make any difference if you leave out the Content-Description header?
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  10. #10
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I delete my cache files and removed that line but still same condition.

  11. #11
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Are you sure that $file holds the correct path to the file?
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  12. #12
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes $file holds the correct path. I check twice. I don't know what is going wrong. Not receiving any error but still not working. Is there any alternative way to do this.

  13. #13
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by rashidr
    Not receiving any error but still not working.
    Just to check - is PHP configured to show errors on your server?
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  14. #14
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, My server is configured to show errors.

  15. #15
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    To be honest, I don't know why it isn't working. I tried it myself, and it worked for me.

    I performed the test in Mozilla Firefox 1.0.4 - which browser are you using?
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  16. #16
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am using Internet explorer 6. It's ok if you don't know. But I want to say thankyou for all of your replies.


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
  •