Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 27

Thread: auto download of a file

  1. #11
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can't. The SitePoint chap was talking about using PHP, which is probably what I'd have to suggest here too.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  2. #12
    Join Date
    Jul 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok...well maybe you can give me a quick lecture if you don't mind. It will be greatly appreciated.

    Let's say I have a .zip file in a protected directory. Once a user has successfully logged in with their email and password in order to download their software, how do I output the '.zip' file to them?

    Is it possible to give me exact code for this? I've been searching around the web, but I can't seem to get something that works. Also...I don't have experience with the HTTP headers of outputting a file using PHP readfile()

    Thanks alot for your help.

  3. #13
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's simple:
    Code:
    $data = file_get_contents('file.zip');
    header('Content-Type: application/x-zip');
    header('Content-Length: ' . strlen($data));
    header('Content-Disposition: attachment; filename=file.zip');
    die($data);
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #14
    Join Date
    Jul 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    It's simple:
    Code:
    $data = file_get_contents('file.zip');
    header('Content-Type: application/x-zip');
    header('Content-Length: ' . strlen($data));
    header('Content-Disposition: attachment; filename=file.zip');
    die($data);
    Great. I appreciate this. And then I just echo $data ? Is that right?

  5. #15
    Join Date
    Jul 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I've tried something different now. You code also basically gave me the same problem. Here is my code :

    PHP Code:
    <?php
    $filename 
    "download/setup4u.zip";
    header("Pragma: public"); // required
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); // required for certain browsers 
    header("Content-Type: application/x-zip");
    // change, added quotes to allow spaces in filenames, by Rajkumar Singh
    header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($filename));
    readfile("$filename");
    exit();
    ?>
    What should I do? Basically I just need a dialog asking them if they want to download. I'm sorry for all these questions, but I really have no idea how to do this. All help is appreciated.

    Here is the URL :

    http://www.pcsnoop.tv/testdownload.php

  6. #16
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Great. I appreciate this. And then I just echo $data ? Is that right?
    No, I've already done that

    Either code should give the standard "do you want to save or open this file" dialog box on most configurations.

    It should be noted that double quotes take significantly longer to parse than single quotes.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #17
    Join Date
    Jul 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Please look at my previous post with the code and the URL.
    It seems to be working perfectly in FireFox, but in IE it just throws out alot of encrypted code. Damn...I'm getting really annoyed by IE...

  8. #18
    Join Date
    Jul 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'll be SO happy if I can get this working.
    I've been struggling with this for a very long time really.
    I know it's simple and all, but yeah...

  9. #19
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Urgh, IE doing its content-type-guessing thing again?
    Well, your server is sending the header:
    Code:
    Content-Type: application/zip
    It should be application/x-zip.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #20
    Join Date
    Jul 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I've tried x-zip but it also doesn't work.
    What is it with IE? I have these problems everyday. I had a JS problem, which I sorted out today thanks to you on another thread. This was also ONLY in IE.
    So what will I do? This dialog works perfectly fine in FireFox, but probably about 75% in the US use IE, and I have to cater for them.

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
  •