Results 1 to 11 of 11

Thread: Downloading files [resolved]

  1. #1

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090

    Downloading files [resolved]

    I know about the header "somthing.zip" thing, but I also know that you should specify stuff like file type etc. how ddo this, also, can you make the browser download a html or jpg file. I don't mean load it in the browser but download it.
    Last edited by Acidic; Apr 21st, 2004 at 05:25 PM.
    Have I helped you? Please Rate my posts.

  2. #2
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  3. #3

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    that's perfect thanks. I did do a search, but didn't find that
    Have I helped you? Please Rate my posts.

  4. #4

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    This code works for getting .zip files, but when I try Dloading a .html file, it simply loads it.
    PHP Code:
    <?
    //Download a file
    $file = $_GET['file'];
    header("Cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");
    header("Content-type: application/x-zip");
    header("Content-disposition: inline; filename=".$file);
    header('Location: '.$file);
    ?>
    this is the code for the button which is clicked:

    PHP Code:
            print "<input type='button' value='Run script' onClick=location.href='/download.php?file=/JavaScript/".$pre.$a.".html'>"
    This code works, as I use it later with a .zip file, and that works fine. I doubt it's the button which is at fault.
    Have I helped you? Please Rate my posts.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    If you set the contenttype to plain text, I think it'll d/l the html, rather than display it..... ????

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    tried "text" and "plain text", neither worked.
    Have I helped you? Please Rate my posts.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    what if you append .txt to the end of the file name????

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Make this change:
    PHP Code:
    // Change this...
    header("Content-disposition: inline; filename=".$file);

    // To...
    header("Content-disposition: attachment; filename=".$file); 
    This is meant to make IE download the file no matter what, I can't be too sure what happens in other browsers.om reading the comments at: http://us2.php.net/manual/en/function.header.php .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  9. #9

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    Originally posted by Electroman
    Make this change:
    PHP Code:
    // Change this...
    header("Content-disposition: inline; filename=".$file);

    // To...
    header("Content-disposition: attachment; filename=".$file); 
    This is meant to make IE download the file no matter what, I can't be too sure what happens in other browsers.om reading the comments at: http://us2.php.net/manual/en/function.header.php .
    no change, not in IE or FX.
    Have I helped you? Please Rate my posts.

  10. #10
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    try this

    PHP Code:
    <?
    //Download a file
    $file = $_GET['file'];
    header("Cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");
    header("Content-type: application/x-zip");
    header("Content-disposition: attachment; filename=".$file);
    readfile($file);
    ?>

  11. #11

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    that worked
    but it seemed to insert dashed before and after $pre. I'm not bothered though, thanks.
    Have I helped you? Please Rate my posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width