[UPHPU] I hate MSIE!
cole at colejoplin.com
cole at colejoplin.com
Fri Sep 15 09:23:55 MDT 2006
Hi Everyone,
There have been a lot of really good suggestions here. I love this
group, great stuff! Since we're throwing options around, here's
another, just for the fun of sharing code. Let's say you want to read
this as a csv multi-column file upload from a form (and you brazenly
want it to work in all browsers). Starting with form stuff, where
enctype is critical...
<form action="read_csv.php" method="post"
enctype="multipart/form-data" name="read_csv" id="read_csv"><input
name="file1" type="file" id="file1" /></form>
then in the read_csv.php file...
// first a function to read csv columns into a multi-dimensional array
function importcsv($file, $head=false, $delim=",", $len=1024) {
$return = false;
$handle = fopen($file, "r");
if ($head) {
$header = fgetcsv($handle, $len, $delim);
}
while (($data = fgetcsv($handle, $len, $delim)) !== FALSE) {
if ($head AND isset($header)) {
foreach ($header as $key=>$heading) {
$row[$heading]=(isset($data[$key])) ? $data[$key] : '';
}
$return[]=$row;
} else {
$return[]=$data;
}
}
fclose($handle);
return $return;
}
// get the file from the post
if(is_uploaded_file($_FILES['file1']['tmp_name'])) {
move_uploaded_file($_FILES['file1']['tmp_name'],
$new_csv_filename_with_path);
// now that the file is on the server where we want it, open it
$csv_array = importcsv($new_csv_filename_with_path); // function above
$max = count($csv_array);
$counter = 1; // used for our loop to get correct array element
do {
$firstValue = $csv_array[$counter][0];
$secondValue = $csv_array[$counter][1];
// assuming we know the csv format here, we've got our data
} while ($max > $counter);
}
...OK, so this is a crazy example, and bit more complicated, and may
not be the best choice for Ed. But I wanted to share a
browser-independent option that isn't at the mercy of Micro$oft. ;)
Plus, it may help someone else later.
-- Cole
Quoting "C. Ed Felt" <ed at thefelts.net>:
> Fellow PHP developers:
>
> I have an annoying little issue with CSV files, mime types and IE and I
> was wondering if any of you have suggestions.
>
> There is nothing secret here so here is the PHP code I am using to pull
> a CSV page from a buffer ($_SESSION["csv"]) to a browser. This code
> works fine in Mozilla (of course) but is broken in MSIE (as usual):
> The url is (not available to you of course):
> http://panel_test.localhost/csvout.php
>
> <?php
> session_start();
> header('Content-Type: application/txt');
> $CSV = $_SESSION["csv"];
> $name = $_SESSION["fileName"];
> header('Content-Length: '.strlen($CSV));
> header('Content-disposition: inline; filename="'.$name.'"');
> echo $CSV;
> ?>
>
> There are two scenarios here, the only constant is that my client is
> Windows XP.
>
> 1. From Apache 2.0.50 (Win 32) I get:
> * Mozilla:
> "You have chosen to open
> <filename>.csv
> ...
> Open With Microsoft Office Excel (default)
> ..."
> I can then open the file just fine in Excel.
> * MSIE (6):
> "File Download
> ...
> Getting File Information:
> csvout from panel_test.localhost
> ...
> ...
> ...
> File Download - Security Warning
> Do you want to save this file?
> Name: csvout
> Type: Unknown File Type
> From: panl_test.localhost
> ...
> While files from the Internet can be useful, this file type
> can potentially harm your computer. If you do not trust the
> source, do not
> save this software. ...
> "
> I then get a blank file called "csvout" that I can save
> (which is of course useless).
> 2. From Apache/2.0.54 (Fedora) Server I get:
> * Mozilla:
> "You have chosen to open
> <filename>.csv
> ...
> Open With Microsoft Office Excel (default)
> ..."
> I can then open the file just fine in Excel.
> * MSIE (6):
> "File Download
> Do you want to open or save this file?
> Name: <filename>.csv
> Type: Microsoft Excel Worksheet, 12.9 KB
> From: <server>
> ....
> "
> I can then either save or directly open the file in Excel
> just fine.
>
> I am at my wits end on this one. I was just wondering if any of you
> have any ideas. Unfortunately I am working in a Windows only shop, so
> I have to get this to work with the WIN32 version of Apache and MSIE
> (6), (the only case that doesn't work).
>
> What I have tried so far:
> http://www.dpawson.co.uk/xsl/sect4/spreadsheet.html
> http://ppewww.ph.gla.ac.uk/~flavell/www/content-type.html
> http://www.microsoft.com/technet/security/Bulletin/MS01-058.mspx
> http://support.microsoft.com/kb/q279667/
> http://msdn.microsoft.com/workshop/networking/moniker/overview/appendix_a.asp
> http://joseph.randomnetworks.com/archives/2004/10/01/making-ie-accept-file-downloads
> http://www.thescripts.com/forum/thread2624.html
>
> Thanks in advance for any help/suggestions.
>
> --
>
> *Thank You,*
>
> *C. Ed Felt*
> (801) 766-8433 (home)
> (801) 420-8879 (cell)
> ed at thefelts.net <mailto:ed at thefelts.net>
> *chat: *edeefelt(aim), edeefelt (yahoo), edeefelt at hotmail.com (msn)
> http://www.thefelts.net <http://www.thefelts.net/>
>
>
> _______________________________________________
>
> UPHPU mailing list
> UPHPU at uphpu.org
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net
More information about the UPHPU
mailing list