Skip to content
Extraits de code Groupes Projets
Valider 40458b7b rédigé par cerdic's avatar cerdic
Parcourir les fichiers

sortir la verification des tailles acceptable dans une fonction surchargeable...

sortir la verification des tailles acceptable dans une fonction surchargeable inc_verifier_taille_document_acceptable_dist qui recoit en plus un flag pour distinguer un logo d'une image normale
parent 477e97d2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -521,78 +521,14 @@ function fixer_fichier_upload($file, $mode = '') {
*/
function verifier_taille_document_acceptable(&$infos) {
// si ce n'est pas une image
if (!$infos['type_image']) {
if (defined('_DOC_MAX_SIZE') and _DOC_MAX_SIZE > 0 and $infos['taille'] > _DOC_MAX_SIZE * 1024) {
return _T(
'medias:info_doc_max_poids',
array(
'maxi' => taille_en_octets(_DOC_MAX_SIZE * 1024),
'actuel' => taille_en_octets($infos['taille'])
)
);
}
} // si c'est une image
else {
if ((defined('_IMG_MAX_WIDTH') and _IMG_MAX_WIDTH and $infos['largeur'] > _IMG_MAX_WIDTH)
or (defined('_IMG_MAX_HEIGHT') and _IMG_MAX_HEIGHT and $infos['hauteur'] > _IMG_MAX_HEIGHT)
) {
$max_width = (defined('_IMG_MAX_WIDTH') and _IMG_MAX_WIDTH) ? _IMG_MAX_WIDTH : '*';
$max_height = (defined('_IMG_MAX_HEIGHT') and _IMG_MAX_HEIGHT) ? _IMG_MAX_HEIGHT : '*';
// pas la peine d'embeter le redacteur avec ca si on a active le calcul des miniatures
// on met directement a la taille maxi a la volee
if (isset($GLOBALS['meta']['creer_preview']) and $GLOBALS['meta']['creer_preview'] == 'oui') {
include_spip('inc/filtres');
$img = filtrer('image_reduire', $infos['fichier'], $max_width, $max_height);
$img = extraire_attribut($img, 'src');
$img = supprimer_timestamp($img);
if (@file_exists($img) and $img !== $infos['fichier']) {
spip_unlink($infos['fichier']);
@rename($img, $infos['fichier']);
list($h, $w) = taille_image($infos['fichier'], true);
$infos['largeur'] = $w;
$infos['hauteur'] = $h;
$infos['taille'] = @filesize($infos['fichier']);
}
}
$is_logo = in_array($infos['mode'], ['logoon', 'logooff']);
if ((defined('_IMG_MAX_WIDTH') and _IMG_MAX_WIDTH and $infos['largeur'] > _IMG_MAX_WIDTH)
or (defined('_IMG_MAX_HEIGHT') and _IMG_MAX_HEIGHT and $infos['hauteur'] > _IMG_MAX_HEIGHT)
) {
return _T(
'medias:info_image_max_taille',
array(
'maxi' =>
_T(
'info_largeur_vignette',
array(
'largeur_vignette' => $max_width,
'hauteur_vignette' => $max_height
)
),
'actuel' =>
_T(
'info_largeur_vignette',
array(
'largeur_vignette' => $infos['largeur'],
'hauteur_vignette' => $infos['hauteur']
)
)
)
);
}
}
$verifier_taille_document_acceptable = charger_fonction('verifier_taille_document_acceptable', 'inc');
$res = $verifier_taille_document_acceptable($infos, $is_logo);
if (defined('_IMG_MAX_SIZE') and _IMG_MAX_SIZE > 0 and $infos['taille'] > _IMG_MAX_SIZE * 1024) {
return _T(
'medias:info_image_max_poids',
array(
'maxi' => taille_en_octets(_IMG_MAX_SIZE * 1024),
'actuel' => taille_en_octets($infos['taille'])
)
);
}
// si erreur, on arrete la
if ($res !== true) {
return $res;
}
// verifier en fonction du mode si une fonction est proposee
......
<?php
/***************************************************************************\
* SPIP, Systme de publication pour l'internet *
* *
* Copyright avec tendresse depuis 2001 *
* Arnaud Martin, Antoine Pitrou, Philippe Rivire, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribu sous licence GNU/GPL. *
* Pour plus de dtails voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
/**
* Gestion des vignettes de types de fichier
*
* @package SPIP\Medias\Vignette
**/
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
* Verifier si le fichier respecte les contraintes de tailles
*
* @param array $infos
* @param bool $is_logo
* @return bool|mixed|string
*/
function inc_verifier_taille_document_acceptable_dist(&$infos, $is_logo = false) {
// si ce n'est pas une image
if (!$infos['type_image']) {
if (defined('_DOC_MAX_SIZE') and _DOC_MAX_SIZE > 0 and $infos['taille'] > _DOC_MAX_SIZE * 1024) {
return _T(
'medias:info_doc_max_poids',
array(
'maxi' => taille_en_octets(_DOC_MAX_SIZE * 1024),
'actuel' => taille_en_octets($infos['taille'])
)
);
}
} // si c'est une image
else {
if ((defined('_IMG_MAX_WIDTH') and _IMG_MAX_WIDTH and $infos['largeur'] > _IMG_MAX_WIDTH)
or (defined('_IMG_MAX_HEIGHT') and _IMG_MAX_HEIGHT and $infos['hauteur'] > _IMG_MAX_HEIGHT)
) {
$max_width = (defined('_IMG_MAX_WIDTH') and _IMG_MAX_WIDTH) ? _IMG_MAX_WIDTH : '*';
$max_height = (defined('_IMG_MAX_HEIGHT') and _IMG_MAX_HEIGHT) ? _IMG_MAX_HEIGHT : '*';
// pas la peine d'embeter le redacteur avec ca si on a active le calcul des miniatures
// on met directement a la taille maxi a la volee
if (isset($GLOBALS['meta']['creer_preview']) and $GLOBALS['meta']['creer_preview'] == 'oui') {
include_spip('inc/filtres');
$img = filtrer('image_reduire', $infos['fichier'], $max_width, $max_height);
$img = extraire_attribut($img, 'src');
$img = supprimer_timestamp($img);
if (@file_exists($img) and $img !== $infos['fichier']) {
spip_unlink($infos['fichier']);
@rename($img, $infos['fichier']);
list($h, $w) = taille_image($infos['fichier'], true);
$infos['largeur'] = $w;
$infos['hauteur'] = $h;
$infos['taille'] = @filesize($infos['fichier']);
}
}
if ((defined('_IMG_MAX_WIDTH') and _IMG_MAX_WIDTH and $infos['largeur'] > _IMG_MAX_WIDTH)
or (defined('_IMG_MAX_HEIGHT') and _IMG_MAX_HEIGHT and $infos['hauteur'] > _IMG_MAX_HEIGHT)
) {
return _T(
'medias:info_image_max_taille',
array(
'maxi' =>
_T(
'info_largeur_vignette',
array(
'largeur_vignette' => $max_width,
'hauteur_vignette' => $max_height
)
),
'actuel' =>
_T(
'info_largeur_vignette',
array(
'largeur_vignette' => $infos['largeur'],
'hauteur_vignette' => $infos['hauteur']
)
)
)
);
}
}
if (defined('_IMG_MAX_SIZE') and _IMG_MAX_SIZE > 0 and $infos['taille'] > _IMG_MAX_SIZE * 1024) {
return _T(
'medias:info_image_max_poids',
array(
'maxi' => taille_en_octets(_IMG_MAX_SIZE * 1024),
'actuel' => taille_en_octets($infos['taille'])
)
);
}
}
return true;
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter