Forum Moderators: phranque
Is it possible to configure Apache to handle images (specifically JPGs) so that users are given a download dialog instead of the image being shown in the window?
I read about Apache's Content Negotiation, but I'm not sure if that is the way to resolve this. Or is this primarily a browser-specific issue?
Thank you for any support!
Andrew Hoffmann
Madison, Wisconsin, USA
To example this from my own browser: when it makes a request it declares it's capabilities within the Accept header (that's the connection with Content Negotiation [webmasterworld.com]). Here is what that looks like for a page-request (If you want to look at this yourself, search for HTTPLiveHeaders, and use a Mozilla/FireFox browser):
Accept: application/x-shockwave-flash,(it is actually all one line, no spaces; I've broken it up so that you can easily pick out the different types)
text/xml,
application/xml,
application/xhtml+xml,
text/html;q=0.9,
text/plain;q=0.8,
video/x-mng,image/png,image/jpeg,image/gif;q=0.2,
text/css,
*/*;q=0.1
Looking now at a request for a single PNG graphic, and stripping out most of the headers:
Request:
GET /graphics/php.png HTTP/1.1
Accept: image/png,*/*;q=0.5
Content-Type: image/png
if( $this->_mimeUse ) {
$ext = strtolower( substr( strrchr( $src, '.' ), 1 ));
// set Content-Type appropriate for the file
// Care! with MS Windows do not use either 'no-store' and/or 'no-cache' for 'Cache-Control:' [hint: PHP sessions set 'no-cache', use session_cache_limiter()] if content type is not in registry under HKEY_CLASSES_ROOT
...
} else {// if( $this->_mimeUse )
// see phpMyAdmin tbl_dump.php
$this->_contentType = (( $this->_browserVersion == 'MSIE' ) or ( $this->_browserVersion == 'OPERA' ))
? 'octetstream'
: 'octet-stream';
}
$this->_contentDispose = ( $this->_browserVersion == 'MSIE' )
? 'inline'
: 'attachment';
...
// MSIE: `Content-Disposition' header important, else will be inline like images;
// MSIE: `Content-Disposition: attachment' forces download
// MSIE: `Content-Disposition:' filename must not contain `Web', `Browser' or `WebBrowser' (?)
// Content-Type MUST precede Content-Disposition
// no quotes around filename in $_contentDispose, even if spaces in name
if( $this->_mimeUse )
header( 'Content-Type: '. $this->_contentType );
else
header( 'Content-Type: application/'. $this->_contentType );
header( 'Content-Disposition: '. $this->_contentDispose .'; filename='. $this->destFileName );
...
if( $this->_browserVersion!= 'MSIE' )
header( 'Pragma: no-cache' );