Computing.Net > Forums > Web Development > PHP JPEG file download on Mac(IE)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP JPEG file download on Mac(IE)

Reply to Message Icon

Name: neutron
Date: March 9, 2005 at 09:17:20 Pacific
OS: Mac OSX
CPU/Ram: 512Mb
Comment:

I am trying to download a JPG file through a php page. The code is pretty straight forward, it obtains the filename from the query string, reads the file and outputs to the browser. Here is the code:

<?php
$filename = $_GET["file"];
$bytes = filesize("PATH_TO_FOLDER/$filename");
header("Content-type: application/jpg");
header("Content-disposition: attachment; filename=\"$filename\"");
header("Content-length: $bytes");
//Read the file and output to browser
@readfile("PATH_TO_FOLDER/$filename");
//Code to record the download in database
?>

Originally I had "Content-type: image/jpeg"), but later on changed to "application/jpg" after reading through some forums on web. Both the content-types work fine in all browsers on a Windows PC, but they behave very differently with IE5.2 on MacOSX and IE5.1 on Mac OS9. The "Save As.." box does not open and the image gets displayed directly on the window. If I try to save the image by Ctrl+Click and Download to Disk, it shows the filename as "download.php" instead of the correct name "FILENAME.jpg" given in the Content-disposition header.

I did a lot of google and read in several forums that IE on Mac ignores the Content-disposition header. Is there any workaround for this. My aim is to display the "Save As.." dialog box on Mac IE (OSX and OS9), display the correct filename in the save as dialog box and allow the user to save the file through the dialog box.

(In Mozilla (Mac) it will download the file (but you have to be very quick as it tends to close the "What should Mozilla do with this file?" dialog quickly if you don't select the 'save' option and click 'ok'). Safari seems to be the only browser happy to download a .jpg file onto the disk.)

Any suggestions or pointers would be appreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: anonproxy
Date: March 9, 2005 at 23:41:38 Pacific
Reply:

"I did a lot of google and read in several forums that IE on Mac ignores the Content-disposition header."

That's a notorious (and now older) browser. I've heard of (and seen) code that forces a file download dialogue. Mostly the right header information. Google readily provides this ("force download"). You can try these hacks, but it is likely this behavior is engrained and their is no client-side fix. At some point, your hands are tied.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: PHP JPEG file download on Mac(IE)

My site won't open on Mac IE www.computing.net/answers/webdevel/my-site-wont-open-on-mac-ie/1807.html

Automatic Download on Page Load www.computing.net/answers/webdevel/automatic-download-on-page-load/2772.html

making .zip files downloadable?? www.computing.net/answers/webdevel/making-zip-files-downloadable/1965.html