![]() |
PHP Gurus
I'm using this function to send a file to my users :
function send_file($name) { ob_end_clean(); $path = $name; if (!is_file($path) or connection_status()!=0) return(FALSE); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header("Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Content-Type: application/octet-stream"); header("Content-Length: ".(string)(filesize($path))); header("Content-Disposition: inline; filename=$name"); header("Content-Transfer-Encoding: binary\n"); if ($file = fopen($path, 'rb')) { while(!feof($file) and (connection_status()= =0)) { print(fread($file, 1024*8)); ob_flush(); } fclose($file); } return((connection_status()= =0) and !connection_aborted()); } But for some reason if I try to open it without saving it on my disk it will causes an error. (Invalid Zip file) But if I save the file first and then open it everything works just fine. How can I fix that ? |
Quote:
Im not totally sure - but I think it could be the mime type setting in your apache config file that is the issue. That could be a start for you to Google from - but I could be way off. |
Quote:
header("Content-Type: application/zip"); A list of other content types can be found just over half way down the page here: http://www.expertsrt.com/tutorials/M...P_headers.html |
Was a nice Idea but it doesn't works either :-(
|
bump.....
|
If I open a zip file when prompted by my browser during testing (rather than save it), it opens fine for me (using WinRAR as my archiver on my pc here). The same zip file also opens fine if I actually save it to disk when prompted by the browser. This is using Firefox v1.5.0.4. The code does not work properly at all for me in IE6, but rather gives a browser error after trying to send the page (whatever.php where your function is sitting) itself.
My guess is that your specific combination of headers used so as not to cache the file being downloaded are the problem for you. You're telling the browser not to cache a copy of the file, which is fine if you're saving it to disk locally. However, if you try and have the browser just open the file without having cached it, it will probably choke depending on browser behaviour. There are varying combinations of http headers you can use in your PHP scripts to avoid having files be cached on the local browser; some of them are browser specific (IE one way, most other browsers another way), so on past scripts i can remember doing a check for IE before sending appropriate headers for tools like yours. Read through the PHP documentation on headers for more info : http://ca3.php.net/header |
Your right ! it seems to works fine with FireFox.
It try a lot of cache-related header but I can't seem to get IE to works. I just don't get it ! |
why not a simple redirect to a physical file location?
|
Quote:
Impossible to do if you redirect to the file... |
bump. php pro's time to step up! :thumbsup good luck qw12er. :)
|
thanks for all the bump.
bump for myself :-) |
bump
5678 |
Sorry to bump this an other time but I realy need a solution :-(
|
Quote:
The more I think about it the I think that is the issue. If you dont have access to your Apache configs then try this in a .htaccess file AddType zip file zip |
Quote:
|
If you replace all of the header() lines you used with the following ones, it works correctly in IE6 and Firefox.
header('Cache-Control: '); header('Pragma: '); header("Content-Type: application/force-download"); header("Content-length: " . (string)(filesize($path))); header("Content-Disposition: attachment; filename=" . $path); Test it yourself and see how it works out for you. |
I don't understand why but it does works !!!
Thanks DuckDuckGoose. |
| All times are GMT -7. The time now is 03:24 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123