Skip to content
Extraits de code Groupes Projets
Valider 9d860273 rédigé par cerdic's avatar cerdic Validation de marcimat
Parcourir les fichiers

feat: Permettre de fournir le nom de l’attachment à `spip_livrer_fichier()`

Par défaut si on envoie juste `true` c'est le basename du fichier

Refs: #5301
(cherry picked from commit 53d64124)
parent 60012328
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -28,7 +28,7 @@ if (!defined('_ECRIRE_INC_VERSION')) {
* @param string $fichier
* @param string $content_type
* @param array $options
* bool $attachment
* bool|string $attachment
* int $expires
* int|null range
* @throws Exception
......@@ -38,7 +38,7 @@ function spip_livrer_fichier($fichier, $content_type = 'application/octet-stream
$defaut = [
'attachment' => false,
'expires' => 3600,
'range' => null
'range' => null,
];
$options = array_merge($defaut, $options);
if (is_numeric($options['expires']) and $options['expires'] > 0) {
......@@ -49,7 +49,7 @@ function spip_livrer_fichier($fichier, $content_type = 'application/octet-stream
$options['range'] = $_SERVER['HTTP_RANGE'];
}
spip_livrer_fichier_entetes($fichier, $content_type, $options['attachment'] && !$options['range'], $options['expires']);
spip_livrer_fichier_entetes($fichier, $content_type, ($options['attachment'] && !$options['range']) ? $options['attachment'] : false, $options['expires']);
if (!is_null($options['range'])) {
spip_livrer_fichier_partie($fichier, $options['range']);
......@@ -65,7 +65,7 @@ function spip_livrer_fichier($fichier, $content_type = 'application/octet-stream
* @see spip_livrer_fichier()
* @param string $fichier
* @param string $content_type
* @param false $attachment
* @param bool|string $attachment
* @param int|string $expires
*/
function spip_livrer_fichier_entetes($fichier, $content_type = 'application/octet-stream', $attachment = false, $expires = 0) {
......@@ -81,7 +81,7 @@ function spip_livrer_fichier_entetes($fichier, $content_type = 'application/octe
}
if ($attachment) {
$f = basename($fichier);
$f = (is_string($attachment) ? $attachment : basename($fichier));
// ce content-type est necessaire pour eviter des corruptions de zip dans ie6
header('Content-Type: application/octet-stream');
......@@ -94,7 +94,7 @@ function spip_livrer_fichier_entetes($fichier, $content_type = 'application/octe
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
}
else {
$f = basename($fichier);
$f = (is_string($attachment) ? $attachment : basename($fichier));
header("Content-Disposition: inline; filename=\"$f\";");
header('Expires: ' . $expires); // set expiration time
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter