开发者

Images not being showed in IE , firefox/chrome/others are good !

I am in need to use This Class to server multiple files (img/video/mp3) from an article writing site i use , the only and main problem is that : All images in the articles should be displayed by that class , and that this class doesn't show images (initiates a download when called by URL) . I managed to fix that by deleting this line (maybe line开发者_JAVA技巧 107)

header('Content-Disposition:attachment; filename="'.$this->properties["name"].'";');

which served me well in displaying images from chrome and firefox , but IE still initiate a download :( .

is there any way / headers to fix that ?

Edit :

I added the following to the meta type :

case "jpg": $content_type="image/".$file_extension; break; 
case "gif": $content_type="image/".$file_extension; break; 
case "png": $content_type="image/".$file_extension; break; 


With setting Content-Disposition to attachment is actually intended to be used not to display the resource directly:

Bodyparts can be designated `attachment' to indicate that they are separate from the main body of the mail message, and that their display should not be automatic, but contingent upon some further action of the user.

But although the Content-Disposition header field is rather part of MIME and not part of HTTP, it “has been proposed as a means for the origin server to suggest a default filename if the user requests that the content is saved to a file.” (See HTTP/1.1 – 19.5 Additional Features)

Additionally to that, the use of the special media type application/octet-stream is recommended to imply a download:

If this header is used in a response with the application/octet-stream content-type, the implied suggestion is that the user agent should not display the response, but directly enter a `save response as...' dialog.

But since you want to resource to be displayed directly, use the Content-Disposition value inline instead. With this you can use the filename parameter as well to specify a file name different from the URL’s.

See also Julian Reschke’s Test Cases for HTTP Content-Disposition header field and the Encodings defined in RFC 2047 and RFC 2231/5987 for some further information on the encodings used to encode the filename parameter.


My guess is that IE still required a valid Content-Type header (Assuming the class doesn't supply one for images since it was just forcing a download). Probably need to change this piece of code:

switch( $file_extension ) { // the file type
  case "mp3": $content_type="audio/mpeg"; break;
  case "mpg": $content_type="video/mpeg"; break;
  case "avi": $content_type="video/x-msvideo"; break;
  case "wmv": $content_type="video/x-ms-wmv";break;
  case "wma": $content_type="audio/x-ms-wma";break; 
  default: $content_type="application/force-download";
} 

and add the image extensions and their associated MIME type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜