|
|||||||
| PHP Discussion and technical support for using and deploying PHP based websites. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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"; ?> |
|
#2
|
|||
|
|||
|
<?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 |
|
#3
|
||||
|
||||
|
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! |
|
#4
|
|||
|
|||
|
damin it,
i was going to post that.... thats the third time you done that pyro
|
|
#5
|
|||
|
|||
|
but what, what have I post is not good? I bet you it works well for all browsers
__________________
whiteadi |
|
#6
|
||||
|
||||
|
Quote:
__________________
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! |
|
#7
|
|||
|
|||
|
yeah I was just joking man
__________________
whiteadi |
|
#8
|
|||
|
|||
|
Thank you very very very much!!!
I fixed it!!!
|
|
#9
|
|||
|
|||
|
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!! |
|
#10
|
||||
|
||||
|
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 |
|
#11
|
|||
|
|||
|
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. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|