php,apache,downloads,ie,ns,W9x,WNT,Mac,UNIX solved

From: Date: Tue, 09 Jan 2001 00:49:07 +0000
Subject: php,apache,downloads,ie,ns,W9x,WNT,Mac,UNIX solved
Groups: php.general 
Request: Send a blank email to php-general+get-33362@lists.php.net to get a copy of this message
I've been struggling for a while with a problem that I think I've finally solved and would like to get others' opinions on what I've done. My system is a web front end to a client-server robotic tape-based file archive. I've had all kinds of problems getting file viewing and/or downloading to work correctly with various browser and client OS combinations. Some files have extensions in their names and some don't. Some of the extensions make sense to some clients and some don't. I've finally had success with Netscape 4 on UNIX and Netscape 4.73 on Mac OS and various combinations of Explorer 3, 4, and 5 on Windows 95, 98, NT, and Mac OS. Those are all I have access to right now. Once the user has logged in, he/she sees what appears to be a UNIX directory list. Navigation is by clicking on links to change directories. These links look something like: dms.php?dirname1/dirname2/newdir The dms.php script processes the args, interacts with the backend, and displays a new page displaying the contents of the chosen directory. Once a file is found, the user clicks that link. File links look like: getfile.php/dirname1/dirname2/filename.ext I use the $PATH_INFO variable inside the getfile.php script to identify the file. (I started with the ? like in the dms.php directory handling script but changed when I first started having problems downloading files with some clients. Now that everything appears to work I haven't gone back and tried changing the $PATH_INFO approach back to processing the command line args. Any opinions on which approach is more robust?) I retrieve the specified file from the backend (to a private cache directory) and ship it across the network to the browser using: $x = array(); $x = stat( "$y" ); header( "Accept-Ranges: bytes" ); header( "Content-Length: " . $x[7] ); header( "Connection: close" ); header( "Content-Type: " . FindMime($y) ); readfile( "$y" ); The FindMime function is one I wrote that takes the suffix of the filename and looks it up in a table. It returns a string like "application/msword" or "image/jpeg". (I used the conf/mime.types file that came with Apache as a starting point.) If there is no extension or it can't find a match it sends "application/octet-stream". This mostly worked. The problem was on IE on Windows. If you click on a link you get a dialog that says "Open from current location" or "Save this file to disk". The Save this file worked correctly (as did right clicking and selecting "Save target as") on all combinations except IE4/W98. The "Open from current location" did not work on IE 5 either. The solution turned out to be that I had to turn off the "nocache" option in the php.ini file used by Apache/PHP when the daemon starts up. The actual line I changed was almost at the end of the file and looked like: session.cache_limiter = nocache ; I just moved the ; before the nocache to turn the default caching back on. After doing this though I had to add specific nocache headers in my php scripts where I actually wanted client side caching turned off. I used the example from the php.net documentation: header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); // Date in the past header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" ); // always modified header( "Cache-Control: no-cache, must-revalidate" ); // HTTP/1.1 header( "Pragma: no-cache" ); // HTTP/1.0 Any comments? Is there a proper place for this kind of example to be written up and submitted? --- Bill Rausch, Software Development, Unix, Mac, Windows Numerical Applications, Inc. 509-943-0861 bill@numerical.com

« previous php.general (#33362) next »