note 41615 modified in features.file-upload by aidan
| From: | aidan@php.net | Date: | Thu, 05 Aug 2004 07:45:02 +0000 |
| Subject: | note 41615 modified in features.file-upload by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73975@lists.php.net to get a copy of this message | ||
IE on the Mac is a bit troublesome. If you are uploading a file with an unknown file suffix, IE
uploads the file with a mime type of "application/x-macbinary". The resulting file
includes the resource fork wrapped around the file. Not terribly useful.
The following code assumes that the mime type is in $type, and that you have loaded the file's
contents into $content. If the file is in MacBinary format, it delves into the resource fork
header, gets the length of the data fork (bytes 83-86) and uses that to get rid of the resource
fork.
(There is probably a better way to do it, but this solved my problem):
<?php
if ($type == 'application/x-macbinary') {
if (strlen($content) < 128) die('File too small');
$length = 0;
for ($i=83; $i<=86; $i++) {
$length = ($length * 256) + ord(substr($content,$i,1));
}
$content = substr($content,128,$length);
}
?>
--was--
IE on the Mac is a bit troublesome. If you are uploading a file with an unknown file suffix, IE
uploads the file with a mime type of "application/x-macbinary". The resulting file
includes the resource fork wrapped around the file. Not terribly useful.
The following code assumes that the mime type is in $type, and that you have loaded the file's
contents into $content. If the file is in MacBinary format, it delves into the resource fork
header, gets the length of the data fork (bytes 83-86) and uses that to get rid of the resource
fork.
(There is probably a better way to do it, but this solved my problem):
if ($type == 'application/x-macbinary') {
if (strlen($content) < 128) die('File too small');
$length = 0;
for ($i=83; $i<=86; $i++) {
$length = ($length * 256) + ord(substr($content,$i,1));
}
$content = substr($content,128,$length);
}
http://php.net/manual/en/features.file-upload.php