Page 1 sur 1

probleme avec script d upload

Posté : 02 sept. 2012, 19:21
par Invité
Bonjour,

Je suis nouveau sur le forum, je ne connais pas grand-chose en php et là je me retrouve avec un énorme problème ..

Après avoir passé plusieurs heures à lire ici et ailleurs pour trouver une solution je n'en ai point trouvé donc je me tourne vers vous afin je l'espère trouver de l'aide et qui sait une solution ..

Voilà mon problème .. en fait mon script d'upload d'images fonctionnent très bien en local .. mais dès que je l'up sur le serveur, la par contre il ne fonctionne pas du tout .. Alors que sur une autre partie du site il fonctionne parfaitement

Je vous colle ci-dessous le code ainsi que le long message d'erreur.. comme je vous l'ai dit je suis débutant, svp soyez indulgent avec moi.

le code de la page
<?php require_once('../Connections/chezyaya.php'); ?>
<?php require_once('../Connections/chezyaya.php');
mysql_query ("SET NAMES UTF8");
if($_GET['image'] != '')
{
$image = $_GET['image'];
if(file_exists($image))
{
unlink($image);
}
}?>
<?php require_once('../Connections/chezyaya.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ajout")) {
$insertSQL = sprintf("INSERT INTO articles (famille, id_categorie, prix, statut_promo, px_promo, nouveau, `desc`) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['famille'], "text"),
GetSQLValueString($_POST['id_categorie'], "int"),
GetSQLValueString($_POST['prix'], "text"),
GetSQLValueString($_POST['statut_promo'], "text"),
GetSQLValueString($_POST['px_promo'], "text"),
GetSQLValueString($_POST['nouveau'], "text"),
GetSQLValueString($_POST['desc'], "text"));

mysql_select_db($database_chezyaya, $chezyaya);
$Result1 = mysql_query($insertSQL, $chezyaya) or die(mysql_error());

$insertGoTo = "catalogue.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_chezyaya, $chezyaya);
$query_categorie_chaussure = "SELECT * FROM categories WHERE famille = 'chaussures-dame' ORDER BY categorie ASC";
$categorie_chaussure = mysql_query($query_categorie_chaussure, $chezyaya) or die(mysql_error());
$row_categorie_chaussure = mysql_fetch_assoc($categorie_chaussure);
$totalRows_categorie_chaussure = mysql_num_rows($categorie_chaussure);

mysql_select_db($database_chezyaya, $chezyaya);
$query_categories = "SELECT * FROM categories";
$categories = mysql_query($query_categories, $chezyaya) or die(mysql_error());
$row_categories = mysql_fetch_assoc($categories);
$totalRows_categories = mysql_num_rows($categories);
?>

<?
$last_id = mysql_insert_id();
switch($_FILES['fichier']['type'])
{
case "image/jpg" OR "image/pjpeg":
$ext=".jpg";
break;
case "image/gif" :
$ext="gif";
break;
case "image/png":
$ext=".png";
break;
case "application/pdf":
$ext=".pdf";
break;

}
if($_FILES['fichier']['error'] == 0)
{
if($_FILES['fichier']['type'] =="image/jpeg" OR $_FILES['fichier']['type'] =="image/pjpeg")
$temp=$_FILES['fichier']['tmp_name'];
$chemin="../images/articles/grandes/";
$chemin_vignette="../images/articles/petites/";
$nom_file= $last_id.$ext;
$destination=$chemin.$nom_file;
$destination_vignette = $chemin_vignette.$nom_file;

move_uploaded_file($temp,$destination);
//redimension image
$max_width = 600;
$max_height = 600;

$file=$destination;

$size=getimagesize($file);
$width=$size[0];
$height=$size[1];

$x_ratio=$max_width/$width;
$y_ratio=$max_height/$height;

if (($width <= $max_width) && ($height <= $max_height))
{
$tn_width=$width;
$tn_height=$height;
}
else if (($x_ratio * $height) < $max_height)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}

$src = imagecreatefromjpeg($file);
$dst = imagecreatetruecolor($tn_width,$tn_height);
//imagecreatetruecolor
imagecopyresized($dst,$src,0,0,0,0,$tn_width,$tn_height,$width,$height);
//header("content-type: image/jpeg");
$couleurgris = imagecolorallocate($dst, 125, 125, 125);
imagestring($dst, 2, 2, 2, "", $couleurgris);
imagejpeg($dst,$file, 100); //écrit l'image réduite sur le serveur
//imagejpeg($dst, null, -1); //renvoie l'image au navigateur
imagedestroy($src);
imagedestroy($dst);
///chmod($destination,0707);

//redimension vignette

$max_width = 150;
$max_height = 200;

$file=$destination;
$sortie = $destination_vignette;

$size=getimagesize($file);
$width=$size[0];
$height=$size[1];

$x_ratio=$max_width/$width;
$y_ratio=$max_height/$height;

if (($width <= $max_width) && ($height <= $max_height))
{
$tn_width=$width;
$tn_height=$height;
}
else if (($x_ratio * $height) < $max_height)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}

$src = imagecreatefromjpeg($file);
$dst = imagecreatetruecolor($tn_width,$tn_height);
//imagecreatetruecolor
imagecopyresized($dst,$src,0,0,0,0,$tn_width,$tn_height,$width,$height);
//header("content-type: image/jpeg");
$couleurgris = imagecolorallocate($dst, 125, 125, 125);
imagestring($dst, 2, 2, 2, "", $couleurgris);
imagejpeg($dst,$sortie, 100); //écrit l'image réduite sur le serveur
//imagejpeg($dst, null, -1); //renvoie l'image au navigateur
imagedestroy($src);
imagedestroy($dst);
//chmod($destination,0707);



}
else{
echo "Erreur lors de l'envoie";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administration</title>
<link href="styles.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body>
<div id="general">
<h1>Bienvenue dans l'administration de votre site internet !</h1>
<ul id="menu">
<li><a href="gestion_chaussure.php">Administration</a></li>

</ul>

<div id="gestion">
<h2>Ajouter un article:</h2>
<form action="<?php echo $editFormAction; ?>" name="ajout" method="POST" enctype="multipart/form-data" id="ajout">
<p>Famille : <select name="famille" id="famille">
<option value="chaussures-dame">chaussures-dame</option>
<option value="accessoires">accessoires</option>
<option value="pret-a-porter-dame">pret-a-porter-dame</option>
<option value="articles-cadeaux">articles-cadeaux</option>
</select>
</p>
<p>Catégorie : <select name="id_categorie" id="id_categorie">
<?php
do {
?>
<option value="<?php echo $row_categories['id_categorie']?>"><?php echo $row_categories['categorie']?></option>
<?php
} while ($row_categories = mysql_fetch_assoc($categories));
$rows = mysql_num_rows($categories);
if($rows > 0) {
mysql_data_seek($categories, 0);
$row_categories = mysql_fetch_assoc($categories);
}
?>
</select></p>

<p>Prix : <input name="prix" type="text" id="prix" /></p>
<p>Statut promo : <select name="statut_promo" id="statut_promo">
<option value="OFF">OFF</option>
<option value="ON">ON</option>
</select></p>
<p>Prix promo : <input name="px_promo" type="text" id="px_promo" /></p>
<p>Nouveauté : <select name="nouveau" id="nouveau">
<option value=" "> </option>
<option value="New">New</option>
</select></p>
<p>Description : <textarea name="desc" cols="50" rows="5" id="desc"></textarea></p>
<p>Photo : <input name="fichier" type="file" id="fichier" />
</p>
<p><input name="Valider" type="submit" id="Valider" value="Valider" /></p>
<input type="hidden" name="MM_insert" value="ajout" />
</form>
</div>

</div><!--ferme general -->
</body>
</html>
<?php
mysql_free_result($categorie_chaussure);

mysql_free_result($categories);
?>
message d'erreur

Code : Tout sélectionner

Warning: getimagesize(../images/articles/grandes/0): failed to open stream: No such file or directory in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 150 Warning: Division by zero in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 154 Warning: Division by zero in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 155 Warning: imagecreatefromjpeg(../images/articles/grandes/0): failed to open stream: No such file or directory in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 172 Warning: imagecreatetruecolor(): Invalid image dimensions in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 173 Warning: imagecopyresized() expects parameter 1 to be resource, boolean given in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 175 Warning: imagecolorallocate() expects parameter 1 to be resource, boolean given in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 177 Warning: imagestring() expects parameter 1 to be resource, boolean given in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 178 Warning: imagejpeg() expects parameter 1 to be resource, boolean given in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 179 Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 181 Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 182 Warning: getimagesize(../images/articles/grandes/0): failed to open stream: No such file or directory in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 193 Warning: Division by zero in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 197 Warning: Division by zero in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 198 Warning: imagecreatefromjpeg(../images/articles/grandes/0): failed to open stream: No such file or directory in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 215 Warning: imagecreatetruecolor(): Invalid image dimensions in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 216 Warning: imagecopyresized() expects parameter 1 to be resource, boolean given in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 218 Warning: imagecolorallocate() expects parameter 1 to be resource, boolean given in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 220 Warning: imagestring() expects parameter 1 to be resource, boolean given in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 221 Warning: imagejpeg() expects parameter 1 to be resource, boolean given in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 222 Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 224 Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 225
En espérant trouver l'aide tant espérée je remercie par avance ceux qui m'aideront

Re: probleme avec script d upload

Posté : 02 sept. 2012, 19:30
par axel148
oooo^pppsss je n avais pas vu que je n'etais pas connecté pour le poste

Re: probleme avec script d upload

Posté : 03 sept. 2012, 11:00
par moogli
salut,
Warning: getimagesize(../images/articles/grandes/0): failed to open stream: No such file or directory in /customers/8/e/2/chezya-ya.be/httpd.www/ya-ya-admin/chaussure_ajout.php on line 150
le fichier n'existe pas, pour la fonction getimagesize à la ligne 150

$size=getimagesize($file);

en claire $file ne référence pas un fichier.

il te faut debugger ton script

tu peux voir comment faire ici ou =ttp://julien-pauli.developpez.com/tuto ... xdebug/]la avec un debuguer (le mieux)
(je pense que le move_uploaded_file ne fait pas son taff, il faut vérifier ce que retourne cette fonction avant de faire la suite (si false => boulette).

as tu bien créé les répertoire sur ton hébergement ?
$last_id = mysql_insert_id();
Description

int mysql_insert_id ([ resource $link_identifier = NULL ] )
Retourne le dernier identifiant généré par un champ de type AUTO_INCREMENT, sur la connexion MySQL courante ou sûr la connexion spécifiée par link_identifier (habituellement, une requête de type INSERT).

Valeurs de retour

L'ID généré pour une colonne AUTO_INCREMENT par la dernière requête en cas de succès, 0 si la dernière requête n'a pas généré de valeur AUTO_INCREMENT, ou FALSE si aucune connexion MySQL n'a été établie.
donc tu devrait toujours avoir zéro.

j'ajoute que l'extension mysql étant déprécié il serait plus intéressant d'utiliser l'extension mysqli (ou PDO).

Afin d'être certain de ce qui se passe je te conseil de vérifier que ton error_reporting est bien àE_ALL le temps du dev / test afin de bien voir toute les erreurs.


@+