SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict molder101's Avatar
    Join Date
    Apr 2004
    Location
    dorothy
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IE7 problem displaying PDF, etc filetypes

    I ran into a problem with a script that displays documents when we upgraded (I prefer to think downgraded) our browsers to IE7.

    *All strings are defined previously by querying a MYSQL db.*

    PHP Code:
    // try to conceal our content type
    header('Content-Type: '$mime);
            
    // cue the client that this should be displayed inline
    header('Content-Disposition: inline; filename='.$short_filename);
            
    // we don't support byte serving
    header('Accept-Ranges: none');
            
    header('Content-Length: '.$length);
    fpassthru$fp ); // this closes $fp 
    What the script is supposed to do is grab the file requested and display it inline on the screen... whether it be a pdf, doc, or xls doc. This works fine in Netscape/Firefox and worked fine in IE6... obviously something has changed in IE7 that is causing DOCs and XLSs not to open (sometimes PDFs do).

    Anyone have any idea? Did mime types change in IE7?

    Thanks,
    Mike
    Michael R. Sikora
    www.blue-eyedesign.com
    {redesigning web design}

  2. #2
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IE can be really bad about loading files through a proxy script like this. Below is the code I use, that seems to work most of the time. The headers have to be just so, and sometimes it still isn't enough.

    PHP Code:
        function getMimeType($file)
        {
            
    $nameArr explode('.',$file);
            
    $ext $nameArr[(count($nameArr) - 1)];
            switch(
    strtolower($ext))
            {
                case 
    'pdf':
                    
    $type 'application/pdf';
                    break;
                case 
    'jpg':
                    
    $type 'image/jpeg';
                    break;
                case 
    'jpeg':
                    
    $type 'image/jpeg';
                    break;
                case 
    'gif':
                    
    $type 'image/gif';
                    break;
                case 
    'mp4':
                    
    $type 'application/mpeg4-generic';
                    break;
                case 
    'mp3':
                    
    $type 'audio/mpeg';
                    break;
                case 
    'tiff':
                    
    $type 'image/tiff';
                    break;
                case 
    'png':
                    
    $type 'image/png';
                    break;
                case 
    'csv':
                    
    $type 'text/csv';
                    break;
                case 
    'txt':
                    
    $type 'text/plain';
                    break;
                case 
    'xml':
                    
    $type 'text/xml';
                    break;
                case 
    'html':
                    
    $type 'text/html';
                    break;
                case 
    'doc':
                    
    $type 'application/msword';
                    break;
                case 
    'zip':
                    
    $type 'application/zip';
                    break;
                case 
    'jpeg2000':
                    
    $type 'image/jp2';
                    break;
                case 
    'rtf':
                    
    $type 'text/rtf';
                    break;
                case 
    'mov':
                    
    $type 'video/quicktime';
                    break;
                case 
    'xls':
                    
    $type 'application/excel';
                    break;
                case 
    'ppt':
                    
    $type 'application/powerpoint';
                    break;
                case 
    'wav':
                    
    $type 'audio/x-wav';
                    break;
                case 
    'aiff':
                    
    $type 'audio/aiff';
                    break;
                case 
    'mid':
                    
    $type 'audio/x-midi';
                    break;
                case 
    'bmp':
                    
    $type 'image/bmp';
                    break;
                case 
    'mpeg':
                    
    $type 'video/mpeg';
                    break;
                case 
    'mpg':
                    
    $type 'video/mpeg';
                    break;
                case 
    'avi':
                    
    $type 'x-msvideo';
                    break;
                case 
    'pub':
                    
    $type 'application/x-mspublisher';
                    break;
                case 
    'sit':
                    
    $type 'application/x-stuffit';
                    break;
                case 
    'tar':
                    
    $type 'application/x-tar';
                    break;
                case 
    'ra':
                    
    $type 'audio/x-pn-realaudio';
                    break;
                case 
    'ram':
                    
    $type 'audio/x-pn-realaudio';
                    break;
                case 
    'tsv':
                    
    $type 'text/tab-separated-values';
                    break;
                case 
    'asf':
                    
    $type 'video/x-ms-asf';
                    break;
                case 
    'wma':
                    
    $type 'audio/x-ms-wma';
                    break;
                case 
    'wmv':
                    
    $type 'video/x-ms-wmv';
                    break;
                case 
    'flv':
                    
    $type 'video/x-flv';
                    break;
                case 
    'swf':
                    
    $type 'application/x-shockwave-flash';
                    break;
                case 
    'fla':
                    
    $type 'application/octet-stream';
                    break;
                default:
                    
    $type 'application/octet-stream';
                    break;
            }
            return 
    $type;
        }
        
        function 
    downloadHeaders($file,$filelen,$mode='I')
        {
            
    // $mode: D = force download, I = attempt inline
            
    $type getMimeType($file);
            
    $mode strtoupper($mode);
            if(isset(
    $_SESSION))
            {
                
    session_cache_limiter('no-cache');
            }
            
    header('pragma: cache');
            
    header('pragma: public');
            
    header('Cache-Control: max-age=0');
            
    header("Cache-Control: private",false); // required for certain browsers 
            
    header('Content-Type: '.$type);
            
    header("Expires: 0");
            if(
    $mode == 'D')
            {
                
    header('Content-Disposition: attachment; filename='.$file);
            }
            else
            {
                
    header('Content-Disposition: inline; filename='.$file);
            }
            
    header("Content-Transfer-Encoding: binary");
            
    header('Content-Length: '.$filelen);
        }
    // use it this way

    // the directory path to the file
    $path '/var/www/htdocs/files/';
    // The file name
    $filename 'filetodownload.pdf';
    // Get the contents
    $doc file_get_contents($path.$filename);
    // load the file inline
    //downloadHeaders($filename,strlen($doc));
    // or force download
    downloadHeaders($filename,strlen($doc),'D');
    echo(
    $doc);
    exit(); 

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I think it's to do with the IE7 default PNG download settings.

    Anyway - don't think of it as downgrading. IE7 completely floors IE6 in everything - especially if you are writing XHTML strict and validated CSS - It's browsers like IE6 holds the web back (Im talking PNG and so many other features that IE6 lacks).
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The PNG handling won't affect .xls and pdf files however.

    I have seen an MS technote that describes the problem but I don't have a link at the moment. The gist of it is the following....

    When you use IE (6 or 7 with a little bit of improvement in 7) to request a file, it actually requests it three times. The first is to put the file contents in a cache, the second is to obtain mimetype and other attributes, and I forget what the third is for.

    Aside from extreme pickiness when it comes to the headers sent, if the image is not cached on the first request, then you will get a blank page. Control of caching of the image is crucial for the script serving it. That causes most of the problems and is a real stupid way to do it.

  5. #5
    SitePoint Addict molder101's Avatar
    Join Date
    Apr 2004
    Location
    dorothy
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Hammer65.

    That code seemed to work. It does seem that microsoft has strapped down which is essentially good. Previously you didnt have to have all the headers in there. Seems like now you do.

    I dont want to come off as hating IE7... it's just a lot of fun "adjusting" problems that arise out of an update.

    Thanks to all... esp Hammer65.

    Mike
    Michael R. Sikora
    www.blue-eyedesign.com
    {redesigning web design}


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •