简体   繁体   中英

Internet Explorer Content-DIsposition filename doesn't work

right now im sending in php (later on replaced with nodejs) the headers for a file download as followed:

    <?php
    // example array for .exe (for IE, doesnt work)
    // i also tried x-msdownload
    $file = array( 'octet-stream', 'download.exe' );
    header( 'HTTP/1.0 200 OK' );
    header( 'Content-Type: application/'.$file[0] );
    // thats the part that doesnt work - i tried inline; attachment; with quotes, without quotes, single quotes, ending ; no ending ;...
    header( 'Content-Disposition: filename="'.$file[1].'";' );
    header( 'Content-Length: '.filesize( $file[1] ) );
    readfile( $file[1] );
    exit;
    ?>

the result is always the same - i rewrite the downloads to a folder like this: /download/123/ - the content-disposition header should reply the correct filename but IE shows as filename "123" and "Unknown File Type"... now even if i rewrite everything after the ID to the folders index.php and request for example: /download/123/something.exe it will still show as download "something" and "Unknown File Type". no matter what i set as content-type or how i order the values of content-disposition.

as far as i could read up thats a common IE problem that just never got fixed - does anyone know a work around for this issue?

thanks!

EDIT: just to make sure everyone knows what i want as correct outcome: IE should get that its a .EXE file and offer a "Run - Save - Cancel" dialog instead of the "Unknown File Type" standard "Find - Save - Cancel" dialog. btw. if i click on find it redirects me to the microsoft page that explains me what x-msdownload is (which is set right now as content-type)...

The Content-Disposition header is incomplete, it must be:

 header("Content-Disposition: inline; filename=xyz.exe");

Filename is just a parameter. You can also try attachment if you want to force the save as dialog.

Also the MIME type shouldn't be application/octet-stream . IIRC it's usually defined as application/x-msdos-program .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM