www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > PHP

    PHP Discussion and technical support for using and deploying PHP based websites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 03-14-2004, 11:10 PM
    la_unt la_unt is offline
    Registered User
     
    Join Date: Mar 2004
    Posts: 9
    How to force Download in IE...

    Hi,

    Would somebody could tell me how to force download in IE? I saw someone did a code (as shown below) and I 've tested it works in Netscape but does not work in IE, so I added some changes on it, but still can;t work in IE! Could sone of you kindly to show me why and how to fix it!

    Thanks a lot!

    =========
    <?PHP
    ....
    if (strstr($HTTP_USER_AGENT,"MSIE")) {
    $attachment = " ";
    } else {
    $attachment = " attachment;";
    }
    $saveasname="extract.xls";
    //header("Content-Type: application/octet-stream");
    header('Content-Type: application/vnd.ms-excel');
    //header("Content-Disposition: attachment; filename=extraction.xls");
    //header('Content-Disposition: $attachment filename="extraction.xls";');
    header('Content-Disposition: $attachment filename="'.$saveasname.'"');
    header('Content-Transfer-Encoding: binary');
    header('Pragma: no-cache');
    header('Expires: 0');
    print "$header\n$data";
    ?>
    Reply With Quote
      #2  
    Old 03-15-2004, 06:41 AM
    whiteadi whiteadi is offline
    Registered User
     
    Join Date: Mar 2003
    Location: Timisoara, Romania
    Posts: 33
    <?php
    // downloading a file
    $filename = $HTTP_GET_VARS['path'];

    // fix for IE catching or PHP bug issue
    header("Pragma: public");
    header("Expires: 0"); // set expiration time
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    // browser must download file from server instead of cache

    // force download dialog
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");

    // use the Content-Disposition header to supply a recommended filename and
    // force the browser to display the save dialog.
    header("Content-Disposition: attachment; filename=".basename($filename).";");

    /*
    The Content-transfer-encoding header should be binary, since the file will be read
    directly from the disk and the raw bytes passed to the downloading computer.
    The Content-length header is useful to set for downloads. The browser will be able to
    show a progress meter as a file downloads. The content-lenght can be determines by
    filesize function returns the size of a file.
    */
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($filename));

    readfile("$filename");
    exit();

    ?>
    __________________
    whiteadi
    Reply With Quote
      #3  
    Old 03-15-2004, 08:09 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    http://www.infinitypages.com/research/download.htm might help, as well.
    __________________

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!
    Reply With Quote
      #4  
    Old 03-15-2004, 09:22 AM
    chris9902 chris9902 is offline
    Registered User
     
    Join Date: Jul 2003
    Location: UK
    Posts: 441
    damin it,

    i was going to post that.... thats the third time you done that pyro
    Reply With Quote
      #5  
    Old 03-15-2004, 09:26 AM
    whiteadi whiteadi is offline
    Registered User
     
    Join Date: Mar 2003
    Location: Timisoara, Romania
    Posts: 33
    but what, what have I post is not good? I bet you it works well for all browsers
    __________________
    whiteadi
    Reply With Quote
      #6  
    Old 03-15-2004, 09:29 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    Quote:
    Originally posted by whiteadi
    but what, what have I post is not good? I bet you it works well for all browsers
    I was simply providing another example - I hadn't tried your code.
    __________________

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!
    Reply With Quote
      #7  
    Old 03-15-2004, 09:39 AM
    whiteadi whiteadi is offline
    Registered User
     
    Join Date: Mar 2003
    Location: Timisoara, Romania
    Posts: 33
    yeah I was just joking man
    __________________
    whiteadi
    Reply With Quote
      #8  
    Old 03-15-2004, 09:27 PM
    la_unt la_unt is offline
    Registered User
     
    Join Date: Mar 2004
    Posts: 9
    Thumbs up

    Thank you very very very much!!!
    I fixed it!!!
    Reply With Quote
      #9  
    Old 12-17-2006, 07:28 PM
    m.i.c. m.i.c. is offline
    Registered User
     
    Join Date: Nov 2006
    Posts: 39
    This is maybe an old topic, but i'm really really desperate in trying to get it work.
    Because i copy and pasted the code above exactly and it doesn't work

    I really tried about 20 'force download scripts' and none has worked so far...
    But i'm hopefull because at least with this script, i already get a download window, where i can choose if i want to save or open the file, but the problem is that php doesn't find the file, because the download window syas that the size of my jpeg is about 500 bytes, which is way too less of course!

    I think it could have something to do with permissions?? Because the php script is in a different directory then the actual picture.

    Can anybody help me please because i've really been looking for a solution for this force download thing for days and days if i add all the hours.....

    THANKS!!
    Reply With Quote
      #10  
    Old 12-17-2006, 09:29 PM
    chazzy's Avatar
    chazzy chazzy is offline
    Working class hero
     
    Join Date: Aug 2005
    Location: The Garden State
    Posts: 5,635
    typically, php runs as the apache user. this is usually "nobody"

    what are the permissions on the file/directory.
    __________________
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time
    Reply With Quote
      #11  
    Old 12-17-2006, 09:41 PM
    m.i.c. m.i.c. is offline
    Registered User
     
    Join Date: Nov 2006
    Posts: 39
    thanks for your reply.
    all the permissions are set to 755, so i don't think that could be the problem.

    I have been digging into this problem the last few hours and this is what i discovered :

    appearantly the problem is that the 'readfile' function, doesn't have permission to read the pic that i want , 'open_basedir restriction in effect'

    I've been looking on the php.net site and i found that the problem might be that the openbase directory is put to the wrong value (i've checked this for my ISP and its value is something with 'temp', so definitely not the directory where my pictures are)

    So i think that's why it won't work
    The solution would be that i have all my pictures in the same directory as this php script, but unfortunately i can't do that.

    So i wrote an email to my ISP to ask if and how i can adjust this php.ini file (because appearently it depends from ISP to ISP), so that i can change the openbase dir.

    And then hope this solves my problem

    Last edited by m.i.c.; 12-17-2006 at 09:43 PM.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 04:08 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.