Content-Disposition: attachment; filename
Par PlaceOweb le vendredi, janvier 27 2012, 19:07 - Outils Internet - Lien permanent
Comment faire un téléchargement forcé compatible avec tous les navigateurs ?...
Content-Disposition: attachment; filename=xxx
Ma conclusion
if( preg_match("/.*MSIE .*/",$_SERVER["HTTP_USER_AGENT"]) ) { /** * IE (Internet Explorer) * Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3) * Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) */ header('Content-Disposition: attachment; filename="' . rawurlencode($row['fichier_nom']) . '"' ); }else{ /** * FF (Firefox) * Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1 * Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0) Gecko/20100101 Firefox/10.0 * * Opera * Opera/9.80 (Windows NT 6.1; U; fr) Presto/2.10.229 Version/11.61 * * Chrome * Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7 * * Safari * Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7 */ header('Content-Disposition: attachment; filename="' . $row['fichier_nom'] . '"' ); }
RFC
- RFC 2183 Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field
In the extended BNF notation of [RFC 822], the Content-Disposition header field is defined as follows:
disposition := "Content-Disposition" ":"
disposition-type
*(";" disposition-parm)
disposition-type := "inline"
/ "attachment"
/ extension-token
; values are not case-sensitive
disposition-parm := filename-parm
/ creation-date-parm
/ modification-date-parm
/ read-date-parm
/ size-parm
/ parameter
filename-parm := "filename" "=" value
creation-date-parm := "creation-date" "=" quoted-date-time
modification-date-parm := "modification-date" "=" quoted-date-time
read-date-parm := "read-date" "=" quoted-date-time
size-parm := "size" "=" 1*DIGIT
quoted-date-time := quoted-string
; contents MUST be an RFC 822 `date-time'
; numeric timezones (+HHMM or -HHMM) MUST be used
Test Cases for HTTP Content-Disposition header field (RFC 6266) and the Encodings defined in RFCs 2047, 2231 and 5987
Comme d'habitude, on constate que le puta.. de Internet Explorer de Windows nous emmerde ! (Toutes versions confondues de la 6 à 9).
Par exemple si votre fichier contient un point virgule (;), alors le nom du fichier est tronqué. attwithquotedsemicolon