Forum PHP 2017

Voting

Please answer this simple SPAM challenge: six minus four?
(Example: nine)

The Note You're Voting On

steve dot criddle at crd-sector dot com
13 years ago
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);
}
?>

<< Back to user notes page

To Top