par
Cyrano » 04 sept. 2006, 06:18
Dans l'ensemble, ça a l'air convenable. Il reste quelques points de détails comme par exemple des index de tableaux écrits comme des constantes, c'est à dire non encadrés par des séparateurs de chaines de caractères, et l'absence de deux alternatives, regarde ce que ça donne, j,ai commenté pour le second point :
<?php
function ck($img)
{
$image = '';
$location = parse_url($img[1]);
if($location['host'] == $_SERVER['HTTP_HOST'])
{
if(file_exists($_SERVER['HTTP_RACINE'] . $location['path']))
{
$exist = "ok";
$imgpath = $_SERVER['HTTP_RACINE'] . $location['path'];
}
}
else
{
ini_set('allow_url_fopen', '1');
if (@fclose(@fopen($img[1], 'r')))
{
$exist = "ok";
$imgpath = $img[1];
}
// Pas de else ? Que se passe-t-il si l'ouverture du fichier échoue ?
}
if($exist == "ok")
{
$tab = getimagesize($imgpath);
if($tab[0] > 370)
{
$width = ' width="370"';
$linkgd = '<br /><a href="'. $imgpath .'" onclick="window.open(this.href, \'image\', \'width='. $tab[0]+15 .', height='. $tab[1]+15 .', top=5, left=5, toolbar=no, menubar=yes, location=yes, resizable=yes, scrollbars=yes, status=no\'); return false;">Agrandir l\'image</a>';
}
else
{
$width = 'width="'. $tab[0] .'" height="'. $tab[1] .'"';
$linkgd = '';
}
$image = '<img src="'. $img[1] .'"'. $width .' class="imgpost" alt="Image Utilisateur" />'. $linkgd;
}
// Pas de else ? Et si la variable $exist n'est pas définie, que se passe-t-il ?
return $image;
}
?>
Dans l'ensemble, ça a l'air convenable. Il reste quelques points de détails comme par exemple des index de tableaux écrits comme des constantes, c'est à dire non encadrés par des séparateurs de chaines de caractères, et l'absence de deux alternatives, regarde ce que ça donne, j,ai commenté pour le second point :
[php]<?php
function ck($img)
{
$image = '';
$location = parse_url($img[1]);
if($location['host'] == $_SERVER['HTTP_HOST'])
{
if(file_exists($_SERVER['HTTP_RACINE'] . $location['path']))
{
$exist = "ok";
$imgpath = $_SERVER['HTTP_RACINE'] . $location['path'];
}
}
else
{
ini_set('allow_url_fopen', '1');
if (@fclose(@fopen($img[1], 'r')))
{
$exist = "ok";
$imgpath = $img[1];
}
// Pas de else ? Que se passe-t-il si l'ouverture du fichier échoue ?
}
if($exist == "ok")
{
$tab = getimagesize($imgpath);
if($tab[0] > 370)
{
$width = ' width="370"';
$linkgd = '<br /><a href="'. $imgpath .'" onclick="window.open(this.href, \'image\', \'width='. $tab[0]+15 .', height='. $tab[1]+15 .', top=5, left=5, toolbar=no, menubar=yes, location=yes, resizable=yes, scrollbars=yes, status=no\'); return false;">Agrandir l\'image</a>';
}
else
{
$width = 'width="'. $tab[0] .'" height="'. $tab[1] .'"';
$linkgd = '';
}
$image = '<img src="'. $img[1] .'"'. $width .' class="imgpost" alt="Image Utilisateur" />'. $linkgd;
}
// Pas de else ? Et si la variable $exist n'est pas définie, que se passe-t-il ?
return $image;
}
?>[/php]