note 34512 deleted from function.header by sniper

From: Date: Sun, 07 Sep 2003 21:50:01 +0000
Subject: note 34512 deleted from function.header by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55661@lists.php.net to get a copy of this message
Note Submitter: tdbaker@NOSPICEDHAM.ufl.edu ---- I've been using PHP headers to force download of rows from a database as .csv (comma-separated value) spreadsheet files. Since an goal has been cross-browser compatibility, let me share what I have discovered about the behaviors of different browsers: - For some reason, IE 6 for Windows will NOT allow a download if PHP sessions, other headers, or even if file includes are being used. I use sessions to keep track of user authentication, and an off-web-server include connects to the database, and I didn't like the thought of connecting to the db from the download script. Instead, I POSTed all of the data, one row at a time, from the "pre-download" script to the download script, which then runs through the POST fields and echo's each row plus a line break, thus re-creating the file. This may not be a very secure method, but I am a researcher and work with academics, and we hope the data will become public knowledge anyway somewhere on that crazy quest for publication. - Mac browsers are very concerned with MIME types. The following set of headers were required for success with NN4, NN7, and IE5 for the Mac (and also compatible with IE6 for PC): header("Content-type: application/vnd.ms-excel"); // Mac version header("Content-Disposition: attachment; filename=$name"); Where the filename was a .csv format such as "myfile.csv" Each of the three browsers downloaded a MS Excel-associated file (note that IE5 does straight to the download manager without opening a dialog box). - PC browsers do not care about MIME types. The following set of headers were succesful on Win XP Pro with IE6 for PC (as well as Mozilla for Linux), and were required for success with NN4 and NN7 for PC: header("Content-type: application/txt"); // PC version header("Content-Disposition: attachment; filename=$name"); The filename ending with the .csv extension was associated with MS Excel IF it was installed on the local system. Otherwise the user will have to teach Windows to open .csv files with MS Works Spreadsheet or something else, but that is out of the web designer's hands. - Finally, there is the problem of NN 7 for PC wanting to append a ".php" extension to all file types. There has been talk of remedying this by putting a slash (/) at the end of the link, but in my case the script I am posting my data to is being called as an include from another file, so I had something looking like this: <form method='post' action='index.php?run=download'> <input type='hidden' name='database_to_download' value='whatever etc'> The attribute action='index.php?/run=download' didn't work, and after trying several other ineffective combinations, I was able to get results with: action='../my_scripts_folder/?run=download' Where my_scripts_folder is the directory where the calling file index.php resides. This form action was handled properly by Apache 1.3.26 for the six browsers described above. Hope this helps!

« previous php.notes (#55661) next »