image
image

Go Back   macosx.com > Design, Media, Programming & Scripting > Design & Media

Reply
 
Thread Tools
  #1  
Old March 9th, 2005, 03:50 AM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
positron is on a distinguished road
Question JPEG file download via PHP in IE

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.
Reply With Quote
  #2  
Old March 9th, 2005, 03:42 PM
andehlu's Avatar
this modern love
 
Join Date: Feb 2004
Location: torontoCANADA
Posts: 244
Thanks: 0
Thanked 0 Times in 0 Posts
andehlu is on a distinguished road
could you tar or zip the file on the fly and prompt for that download? The browser may know what to do a bit better with this format maybe?

http://us4.php.net/manual/en/ref.zip.php
__________________
site | blog | garageband experiments
Reply With Quote
  #3  
Old March 9th, 2005, 04:25 PM
Who, me?
 
Join Date: Feb 2005
Location: Near to Philly.
Posts: 382
Thanks: 0
Thanked 0 Times in 0 Posts
chornbe is on a distinguished road
*nods* that was what I was going to suggest, too. Wrap it up in some non-media-type file for standard downloading.
Reply With Quote
  #4  
Old March 9th, 2005, 04:26 PM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
positron is on a distinguished road
Thanks for that, although I'd rather users didn't have to deal with unzipping - it may solve my main problem ... I'll give it a shot.
Reply With Quote
  #5  
Old March 9th, 2005, 05:22 PM
Who, me?
 
Join Date: Feb 2005
Location: Near to Philly.
Posts: 382
Thanks: 0
Thanked 0 Times in 0 Posts
chornbe is on a distinguished road
Hmm... I wonder if you could just application/octet-stream it?
Reply With Quote
  #6  
Old March 9th, 2005, 07:04 PM
andehlu's Avatar
this modern love
 
Join Date: Feb 2004
Location: torontoCANADA
Posts: 244
Thanks: 0
Thanked 0 Times in 0 Posts
andehlu is on a distinguished road
how about out putting the image into a pop up window with instructions to right click - save it?
__________________
site | blog | garageband experiments
Reply With Quote
  #7  
Old March 10th, 2005, 02:54 AM
Registered User
 
Join Date: Mar 2004
Posts: 571
Thanks: 0
Thanked 1 Time in 1 Post
aicul is on a distinguished road
Arrow

Lived this also.

Some browsers will automatically process files by their extensions as per previous downloads. IE does this. Download an unknown file (say abc.XYZ) and it will ask you how to process the .XYZ extension. Look carefully the dialog box actually says something like (do this for all files with this extension). From then on all files with extension .XYZ will be processed as indicated in the dialog box. Don't forget that this processing will overrule your PHP code as the setting is local to the client.

I have never-ever, found how to tell IE to change these local settings.

So you don't actually have to repackage, just rename the extension to some unknown extension.
__________________
I'm trying to understand...
Reply With Quote
  #8  
Old April 19th, 2005, 06:08 AM
Registered User
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
phirana is on a distinguished road
Post Did you manage to sort it?

I had a similar problem - it works in every browser. The only one where it's a little dodgy is in IE in OSX, althought you are prompted to download it, the default file is download.php
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 01:39 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.