Solved

downloading on Mac

Posted on 2002-06-21
17
320 Views
Last Modified: 2011-09-20
hi, i've got this downloading problem. my webserver is in a Mac with OSX. i have a page where i show thumbnails of pictures and if the viewers click on a button, the corresponding piture will be downloaded. here's the part of the code:

download.php:
.
.
$path = $dirpath. "/" .$filename;

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$filename);
header("Content-Transfer-Encoding: binary");
$fp = fopen($path, 'rb');
fpassthru($fp);
flush();
.
.

if i access the page from a Windows PC using IE or from a Linux PC using Netscape or Konqueror, it works perfectly fine. but if i access it from a Mac OSX using IE for Mac, it won't download the image file, instead it just shows the image in its original size in the same frame as the download page.
i have no idea what's wrong. please help. thanks!
0
Comment
Question by:pepperoni
  • 9
  • 7
17 Comments
 
LVL 5

Expert Comment

by:dkjariwala
ID: 7100413
Okie.
basically there will be difference in the way browser works. Browser might try to be inteligent and display file if it can recognise file from its extension. its not the fault of code, but more of browser implementation issue.

JD
0
 

Author Comment

by:pepperoni
ID: 7106746
hi JD, thanks for the comment.

I tried accessing downloading the images using different PCs with different Internet Explorer versions. for IE 5.0, the image files are downloaded properly (with the pop up box appearing asking the user to whether to open it from the current location or save it to disk). but with the IE 5.xx's, the gif and jpg files are opened and shown in the browser. that is because the newer version browsers can recognize the the files so they just show them, right? is there a way or tricks with the codes that will stop the browsers from showing the jpg and gif files and have the pop up download box appear instead? pls. help.

thanks.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7106855
Can you try changing your content-type to ...

image/jpeg

or

image/gif

and try again.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7106856
header("Content-type: image/jpeg");

or

header("Content-type: image/gif");


http://www.isi.edu/in-notes/iana/assignments/media-types

http://www.isi.edu/in-notes/iana/assignments/media-types/media-types

is a good list of media types.

0
 

Author Comment

by:pepperoni
ID: 7107140
thanks for the comment RQuadling.

i tried it, but still not working.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7107205
http://www.isi.edu/in-notes/iana/assignments/media-types/application/applefile

describes some issues with sending files to a MAC using MIME.

There is something called AppleSingle and AppleDouble.

But I do not know if the file you want to send has to be a mac file to start with.

What happens if you right click an image and save it. Do you get a single file of the right size? Or is it packaged in some way so that the file knows its type? Does the mac use file extensions like wintel pcs?

Can you try ...

header("Content-Type: application/mac-binhex40; name=\"image.jpg\");


 
0
 

Author Comment

by:pepperoni
ID: 7109497
hi, nope, not a mac file. just image files jpg, gif, pict. the problem is not only with IEs in Mac but also in Windows PCs using Internet Explorers with versions higher than 5.0 . I installed IE 5.5 SP 2 in a Windows PC with IE 5.5 and the problem was gone. :)
0
 

Author Comment

by:pepperoni
ID: 7109498
hi, nope, not a mac file. just image files jpg, gif, pict. the problem is not only with IEs in Mac but also in Windows PCs using Internet Explorers with versions higher than 5.0 . I installed IE 5.5 SP 2 in a Windows PC with IE 5.5 and the problem was gone. :)
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7110039
I must admit, I've NEVER seen the browser fail to show an image if the image is a JPG or a GIF file. The only way to get the file saved is to right click and choose save. I think you used to be able to do shift and left click images, but that doesn't seem to work in IE6.

So.

What happens if you set the name to a type that is NOT an image?

I have to say that you are seeing normal behaviour.

If you can give me the URL of a page that contains images that when I click them, they automatically save, then I can find out what is being sent to me to tell my browser to NOT show it but to ask to save it.

Regards,

Richard Quadling.
0
 

Author Comment

by:pepperoni
ID: 7124271
hi richard,

i do not know any page in the web that does that.
0
 

Author Comment

by:pepperoni
ID: 7124272
hi richard,

i do not know any page in the web that does that.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7124281
Can you show your current code again.

I want to try this on a windows pc. Just to make sure.

Is your browser fully uptodate for it's version? Have you tried the latest version or a different browser?

Exploiting the mime type should be able to force a download. This is how some of the viruses work, by saying they are one thing when they are in fact another.

Regards,

Richard Quadling.
0
 

Author Comment

by:pepperoni
ID: 7137259
hi Richard, sorry for the late reply. anyway, here's the code;

download.php

$path = $dirpath. "/" .$filename;

   header("Content-type: application/octet-stream");
   header("Content-Disposition: attachment; filename=".$filename);
   header("Content-Transfer-Encoding: binary");
   $fp = fopen($path, 'rb');
   fpassthru($fp);
   flush();
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 75 total points
ID: 7137300
I run W2K Pro, with Sambar Server and PHP V4.2.1.

Your script will ask me to save the file rather than download it.

Fair enough.

Can you provide an online version where your script is failing?

Can you try ...

header("Content-Disposition: attachment; filename=unknown");

Do you get an image shown then?

On a PC, this SHOULD give you the "Save" question as there is no extension.

I would assume the same on a mac, but I do not know what links a file to the correct editor/viewer? How does the Mac OS know that a document is to be handled by your WP and images by Photoshop? Is it via the extension (like windows) or what? Are resource files important? Does it scan the actual file and see what is in it and decide upon that to show an image if the header obeys the rules?

Richard.
0
 

Author Comment

by:pepperoni
ID: 7844504
Sorry for being so late.
But thanks a lot for the help.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7844536
No problems. What was your solution?
0
 

Author Comment

by:pepperoni
ID: 7844630
We just let it like that. In the project documentation we wrote it as IE limitation of versions higher than 5.0. Installing IE 5.5 SP2 (with IE 5.5 installed) will solve the problem.

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question