par
krikrizzz » 13 mai 2011, 09:10
Bonjour,
je me pemrets d'écrire sur ce forum car j'ai un petit problème avec mon script de création de thumbnail et d'upload image.
voici l'erreur :
[Fri May 13 08:49:38 2011] [error] PHP Warning: mkdir(): File exists in /data/services/web/xx/www/Admin/Upload_photos.php on line 55
[Fri May 13 08:49:38 2011] [error] PHP Warning: getimagesize(../Fichiers/Photos/xx/8360716139.jpg): failed to open stream: No such file or directory in /data/services/web/xx/www/Admin/Upload_photos.php on line 64
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecreatefromjpeg(../Fichiers/Photos/xx/8360716139.jpg): failed to open stream: No such file or directory in /data/services/web/xx/www/Admin/Upload_photos.php on line 70
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagesx() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 71
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagesy() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 72
[Fri May 13 08:49:38 2011] [error] PHP Warning: Division by zero in /data/services/web/xx/www/Admin/Upload_photos.php on line 74
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecreatetruecolor(): Invalid image dimensions in /data/services/web/xx/www/Admin/Upload_photos.php on line 75
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 76
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagejpeg() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 77
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 78
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 79
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecreatefromjpeg(../Fichiers/Photos/xx/8360716139.jpg): failed to open stream: No such file or directory in /data/services/web/xx/www/Admin/Upload_photos.php on line 84
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagesx() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 85
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagesy() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 86
[Fri May 13 08:49:38 2011] [error] PHP Warning: Division by zero in /data/services/web/xx/www/Admin/Upload_photos.php on line 88
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecreatetruecolor(): Invalid image dimensions in /data/services/web/xx/www/Admin/Upload_photos.php on line 91
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 92
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 93
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagejpeg() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 94
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 95
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 96
voici le script
Code : Tout sélectionner
if (!empty($_FILES)) {
function random($car) {
$string = "";
$chaine = "0123456789";
srand((double)microtime()*1000000);
for($i=0; $i<$car; $i++) {
$string .= $chaine[rand()%strlen($chaine)];
}
return $string;
}
$chaine = random(10);
$targetName = $chaine.'.jpg';
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'];
$targetFile = str_replace('//','/',$targetPath) . $targetName;
// $fileTypes = str_replace('*.','',$_REQUEST['fileext']);
// $fileTypes = str_replace(';','|',$fileTypes);
// $typesArray = split('\|',$fileTypes);
// $fileParts = pathinfo($_FILES['Filedata']['name']);
// if (in_array($fileParts['extension'],$typesArray)) {
// Uncomment the following line if you want to make the directory if it doesn't exist
mkdir(str_replace('//','/',$targetPath.'/miniatures'), 0755, true);
move_uploaded_file($tempFile,$targetFile);
// On créer la miniature sans le logo
/////////////////////////////////////////////////
$affiche=600;
$image = "../Fichiers/Photos/$nom_simplifie_sle/$targetName";
$taille=getimagesize($image);
$largeur=$taille[0];
$hauteur=$taille[1];
//image verticale ou carrée
if ($hauteur >= $largeur) {
$img_max=imagecreatefromjpeg($image);// On va chercher l'originale
$larg=imagesx($img_max);
$haut=imagesy($img_max);
$nhaut=100;
$nlarg=ceil($larg*($nhaut/$haut)); // On en profite pour la redimentionner Ã| 400px de haut.
$img_gd=imagecreatetruecolor ($nlarg, $nhaut); // On créé une image vierge
imagecopyresampled ( $img_gd, $img_max, 0, 0, 0, 0, $nlarg, $nhaut, $larg, $haut);
imagejpeg($img_gd,'../Fichiers/Photos/'.$nom_simplifie_sle.'/miniatures/'.$targetName.'');
imagedestroy($img_gd);
imagedestroy($img_max);
// rajoute le logo sle en bas a droite de l'image
/////////////////////////////////////////////////
$img_water=imagecreatefrompng('../Fichiers/Images_site/logo_photos.png'); // On récupère le logo en PNG
$img_max=imagecreatefromjpeg('../Fichiers/Photos/'.$nom_simplifie_sle.'/'.$targetName.'');// On va chercher l'originale
$larg=imagesx($img_max);
$haut=imagesy($img_max);
$nhaut=600;
$nlarg=ceil($larg*($nhaut/$haut)); // On en profite pour la redimentionner Ã| 600px de haut.
$positionYlogo=$nhaut-60;
$positionXlogo=$nlarg-80;
$img_gd=imagecreatetruecolor ($nlarg, $nhaut); // On créé une image vierge
imagecopyresampled ( $img_gd, $img_max, 0, 0, 0, 0, $nlarg, $nhaut, $larg, $haut);
imagecopyresampled ( $img_gd, $img_water, $positionXlogo, $positionYlogo, 0, 0, 80, 60, 80, 60);
imagejpeg($img_gd,'../Fichiers/Photos/'.$nom_simplifie_sle.'/'.$targetName.'');
imagedestroy($img_gd);
imagedestroy($img_max);
imagedestroy($img_water);
}
//image horizontale ou carrée
else {
$img_max=imagecreatefromjpeg($image);// On va chercher l'originale
$larg=imagesx($img_max);
$haut=imagesy($img_max);
$nlarg=100;
$nhaut=ceil($haut*($nlarg/$larg)); // On en profite pour la redimentionner Ã| 400px de haut.
$img_gd=imagecreatetruecolor ($nlarg, $nhaut); // On créé une image vierge
imagecopyresampled ( $img_gd, $img_max, 0, 0, 0, 0, $nlarg, $nhaut, $larg, $haut);
imagejpeg($img_gd,'../Fichiers/Photos/'.$nom_simplifie_sle.'/miniatures/'.$targetName.'');
imagedestroy($img_gd);
imagedestroy($img_max);
// rajoute le logo sle en bas a droite de l'image
/////////////////////////////////////////////////
$img_water=imagecreatefrompng('../Fichiers/Images_site/logo_photos.png'); // On récupère le logo en PNG
$img_max=imagecreatefromjpeg('../Fichiers/Photos/'.$nom_simplifie_sle.'/'.$targetName.'');// On va chercher l'originale
$larg=imagesx($img_max);
$haut=imagesy($img_max);
$nlarg=600;
$nhaut=ceil($haut*($nlarg/$larg)); // On en profite pour la redimentionner Ã| 600px de haut.
$positionYlogo=$nhaut-60;
$positionXlogo=$nlarg-80;
$img_gd=imagecreatetruecolor ($nlarg, $nhaut); // On créé une image vierge
imagecopyresampled ( $img_gd, $img_max, 0, 0, 0, 0, $nlarg, $nhaut, $larg, $haut);
imagecopyresampled ( $img_gd, $img_water, $positionXlogo, $positionYlogo, 0, 0, 80, 60, 80, 60);
imagejpeg($img_gd,'../Fichiers/Photos/'.$nom_simplifie_sle.'/'.$targetName.'');
imagedestroy($img_gd);
imagedestroy($img_max);
imagedestroy($img_water);
}
$image = '../Fichiers/Photos/'.$nom_simplifie_sle.'/'.$targetName.'';
if (file_exists($image)) {
// Insère les données du formulaire depuis la page ajouter_news.php
$sql1 = "INSERT INTO `FICHIER` (`id_type_fichier`, `id_match`, `id_event`, `nom`, `path`, `commentaire`) VALUES ('1', NULL, '$id_sle', '$chaine', '$targetName', 'Aucun commentaire')";
mysql_query("SET NAMES UTF8");
$req1 = mysql_query($sql1);
$erreur1 = 'Erreur SQL !<br>'.$sql1.'<br>'.mysql_error();
}
echo "1";
}
?>
je tiens à préciser que cela marche sur des petites images, j'ai l'impression que c'est les dimensions de l'image qui posent problemes
Auriez vous une idée ?
Merci par avance pour votre aide.
Bonjour,
je me pemrets d'écrire sur ce forum car j'ai un petit problème avec mon script de création de thumbnail et d'upload image.
voici l'erreur :
[quote]
[Fri May 13 08:49:38 2011] [error] PHP Warning: mkdir(): File exists in /data/services/web/xx/www/Admin/Upload_photos.php on line 55
[Fri May 13 08:49:38 2011] [error] PHP Warning: getimagesize(../Fichiers/Photos/xx/8360716139.jpg): failed to open stream: No such file or directory in /data/services/web/xx/www/Admin/Upload_photos.php on line 64
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecreatefromjpeg(../Fichiers/Photos/xx/8360716139.jpg): failed to open stream: No such file or directory in /data/services/web/xx/www/Admin/Upload_photos.php on line 70
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagesx() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 71
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagesy() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 72
[Fri May 13 08:49:38 2011] [error] PHP Warning: Division by zero in /data/services/web/xx/www/Admin/Upload_photos.php on line 74
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecreatetruecolor(): Invalid image dimensions in /data/services/web/xx/www/Admin/Upload_photos.php on line 75
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 76
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagejpeg() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 77
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 78
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 79
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecreatefromjpeg(../Fichiers/Photos/xx/8360716139.jpg): failed to open stream: No such file or directory in /data/services/web/xx/www/Admin/Upload_photos.php on line 84
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagesx() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 85
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagesy() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 86
[Fri May 13 08:49:38 2011] [error] PHP Warning: Division by zero in /data/services/web/xx/www/Admin/Upload_photos.php on line 88
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecreatetruecolor(): Invalid image dimensions in /data/services/web/xx/www/Admin/Upload_photos.php on line 91
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 92
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 93
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagejpeg() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 94
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 95
[Fri May 13 08:49:38 2011] [error] PHP Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /data/services/web/xx/www/Admin/Upload_photos.php on line 96
[/quote]
voici le script
[code]if (!empty($_FILES)) {
function random($car) {
$string = "";
$chaine = "0123456789";
srand((double)microtime()*1000000);
for($i=0; $i<$car; $i++) {
$string .= $chaine[rand()%strlen($chaine)];
}
return $string;
}
$chaine = random(10);
$targetName = $chaine.'.jpg';
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'];
$targetFile = str_replace('//','/',$targetPath) . $targetName;
// $fileTypes = str_replace('*.','',$_REQUEST['fileext']);
// $fileTypes = str_replace(';','|',$fileTypes);
// $typesArray = split('\|',$fileTypes);
// $fileParts = pathinfo($_FILES['Filedata']['name']);
// if (in_array($fileParts['extension'],$typesArray)) {
// Uncomment the following line if you want to make the directory if it doesn't exist
mkdir(str_replace('//','/',$targetPath.'/miniatures'), 0755, true);
move_uploaded_file($tempFile,$targetFile);
// On créer la miniature sans le logo
/////////////////////////////////////////////////
$affiche=600;
$image = "../Fichiers/Photos/$nom_simplifie_sle/$targetName";
$taille=getimagesize($image);
$largeur=$taille[0];
$hauteur=$taille[1];
//image verticale ou carrée
if ($hauteur >= $largeur) {
$img_max=imagecreatefromjpeg($image);// On va chercher l'originale
$larg=imagesx($img_max);
$haut=imagesy($img_max);
$nhaut=100;
$nlarg=ceil($larg*($nhaut/$haut)); // On en profite pour la redimentionner Ã| 400px de haut.
$img_gd=imagecreatetruecolor ($nlarg, $nhaut); // On créé une image vierge
imagecopyresampled ( $img_gd, $img_max, 0, 0, 0, 0, $nlarg, $nhaut, $larg, $haut);
imagejpeg($img_gd,'../Fichiers/Photos/'.$nom_simplifie_sle.'/miniatures/'.$targetName.'');
imagedestroy($img_gd);
imagedestroy($img_max);
// rajoute le logo sle en bas a droite de l'image
/////////////////////////////////////////////////
$img_water=imagecreatefrompng('../Fichiers/Images_site/logo_photos.png'); // On récupère le logo en PNG
$img_max=imagecreatefromjpeg('../Fichiers/Photos/'.$nom_simplifie_sle.'/'.$targetName.'');// On va chercher l'originale
$larg=imagesx($img_max);
$haut=imagesy($img_max);
$nhaut=600;
$nlarg=ceil($larg*($nhaut/$haut)); // On en profite pour la redimentionner Ã| 600px de haut.
$positionYlogo=$nhaut-60;
$positionXlogo=$nlarg-80;
$img_gd=imagecreatetruecolor ($nlarg, $nhaut); // On créé une image vierge
imagecopyresampled ( $img_gd, $img_max, 0, 0, 0, 0, $nlarg, $nhaut, $larg, $haut);
imagecopyresampled ( $img_gd, $img_water, $positionXlogo, $positionYlogo, 0, 0, 80, 60, 80, 60);
imagejpeg($img_gd,'../Fichiers/Photos/'.$nom_simplifie_sle.'/'.$targetName.'');
imagedestroy($img_gd);
imagedestroy($img_max);
imagedestroy($img_water);
}
//image horizontale ou carrée
else {
$img_max=imagecreatefromjpeg($image);// On va chercher l'originale
$larg=imagesx($img_max);
$haut=imagesy($img_max);
$nlarg=100;
$nhaut=ceil($haut*($nlarg/$larg)); // On en profite pour la redimentionner Ã| 400px de haut.
$img_gd=imagecreatetruecolor ($nlarg, $nhaut); // On créé une image vierge
imagecopyresampled ( $img_gd, $img_max, 0, 0, 0, 0, $nlarg, $nhaut, $larg, $haut);
imagejpeg($img_gd,'../Fichiers/Photos/'.$nom_simplifie_sle.'/miniatures/'.$targetName.'');
imagedestroy($img_gd);
imagedestroy($img_max);
// rajoute le logo sle en bas a droite de l'image
/////////////////////////////////////////////////
$img_water=imagecreatefrompng('../Fichiers/Images_site/logo_photos.png'); // On récupère le logo en PNG
$img_max=imagecreatefromjpeg('../Fichiers/Photos/'.$nom_simplifie_sle.'/'.$targetName.'');// On va chercher l'originale
$larg=imagesx($img_max);
$haut=imagesy($img_max);
$nlarg=600;
$nhaut=ceil($haut*($nlarg/$larg)); // On en profite pour la redimentionner Ã| 600px de haut.
$positionYlogo=$nhaut-60;
$positionXlogo=$nlarg-80;
$img_gd=imagecreatetruecolor ($nlarg, $nhaut); // On créé une image vierge
imagecopyresampled ( $img_gd, $img_max, 0, 0, 0, 0, $nlarg, $nhaut, $larg, $haut);
imagecopyresampled ( $img_gd, $img_water, $positionXlogo, $positionYlogo, 0, 0, 80, 60, 80, 60);
imagejpeg($img_gd,'../Fichiers/Photos/'.$nom_simplifie_sle.'/'.$targetName.'');
imagedestroy($img_gd);
imagedestroy($img_max);
imagedestroy($img_water);
}
$image = '../Fichiers/Photos/'.$nom_simplifie_sle.'/'.$targetName.'';
if (file_exists($image)) {
// Insère les données du formulaire depuis la page ajouter_news.php
$sql1 = "INSERT INTO `FICHIER` (`id_type_fichier`, `id_match`, `id_event`, `nom`, `path`, `commentaire`) VALUES ('1', NULL, '$id_sle', '$chaine', '$targetName', 'Aucun commentaire')";
mysql_query("SET NAMES UTF8");
$req1 = mysql_query($sql1);
$erreur1 = 'Erreur SQL !<br>'.$sql1.'<br>'.mysql_error();
}
echo "1";
}
?>
[/code]
je tiens à préciser que cela marche sur des petites images, j'ai l'impression que c'est les dimensions de l'image qui posent problemes
Auriez vous une idée ?
Merci par avance pour votre aide.