Bonjour , je galère et n''arrive pas à trouver la solution.j'ai trouvé
un script d'upload que j'ai intégré à une formulaire d'insertion pour
enregistrer le nom de l'image dans ma base avec les autres champs et en
plus redimmensionner l'image uploadée .Le script d'upload marche tres
bien seul mais aevc les autres chaps du from ça ne marche pas .il
insere dans la table toutes les valeurs mmeme le nom de l'image mais
pas d'upload de l'image .voilà le script.La seule chose que j'ai
modifiée , c'est <form method="POST"
action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data"> car
quand je mets
cette action ,j'ai une erreur.Merci pour votre aide
<?php
require_once('Connections/conn.php');
if(isset($_POST['Submit']))
{
$size = 150; // the thumbnail height
$filedir =
'/home/sites/site15/web/images/produit/'; // the directory for the
original image
$thumbdir =
'/home/sites/site15/web/images/produit/petites/'; // the directory for
the thumbnail image
$prefix = ''; // the prefix to be added to the original name
$maxfile = '2000000';
$mode = '0777';
$userfile_name = $_FILES['photo_produit']['name'];
$userfile_tmp = $_FILES['photo_produit']['tmp_name'];
$userfile_size = $_FILES['photo_produit']['size'];
$userfile_type = $_FILES['photo_produit']['type'];
if (isset($_FILES['photo_produit']['name']))
{
$prod_img = $filedir.$userfile_name;
$prod_img_thumb = $thumbdir.$prefix.$userfile_name;
move_uploaded_file($userfile_tmp, $prod_img);
chmod ($prod_img, octdec($mode));
$sizes = getimagesize($prod_img);
$aspect_ratio = $sizes[1]/$sizes[0];
if ($sizes[1] <= $size)
{
$new_width = $sizes[0];
$new_height = $sizes[1];
}else{
$new_height = $size;
$new_width = abs($new_height/$aspect_ratio);
}
$destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem
In Creating image');
$srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening
Source Image');
ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg))
or die('Problem In resizing');
ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving');
imagedestroy($destimg);
}
}
//bases champs
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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"] == "form1")) {
$insertSQL = sprintf("INSERT INTO produits (nom_produit,
description_produit, photo_produit, categorie_produit) VALUES (%s, %s,
%s, %s)",
GetSQLValueString($_POST['nom_produit'], "text"),
GetSQLValueString($_POST['description_produit'], "text"),
GetSQLValueString($_POST['photo_produit'], "text"),
GetSQLValueString($_POST['categorie_produit'], "int"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
}
mysql_select_db($database_conn, $conn);
$query_cate = "SELECT * FROM categories";
$cate = mysql_query($query_cate, $conn) or die(mysql_error());
$row_cate = mysql_fetch_assoc($cate);
$totalRows_cate = mysql_num_rows($cate);
mysql_select_db($database_conn, $conn);
$query_produit = "SELECT * FROM produits";
$produit = mysql_query($query_produit, $conn) or die(mysql_error());
$row_produit = mysql_fetch_assoc($produit);
$totalRows_produit = mysql_num_rows($produit);
?>
<!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=iso-8859-1" />
<title>Document sans titre</title>
</head>
<body>
<form method="post" name="form1" action="" enctype="multipart/form-data">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Nom_produit:</td>
<td><input type="text" name="nom_produit" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Description_produit:</td>
<td><textarea name="description_produit" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Photo_produit:</td>
<td><input type="file" name="photo_produit" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Categorie_produit:</td>
<td><select name="categorie_produit">
<?php
do {
?>
<option value="<?php
echo $row_cate['id_categorie']?>"><?php echo
$row_cate['nom_categorie']?></option>
<?php
} while ($row_cate = mysql_fetch_assoc($cate));
$rows = mysql_num_rows($cate);
if($rows > 0) {
mysql_data_seek($cate, 0);
$row_cate = mysql_fetch_assoc($cate);
}
?>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insérer l'enregistrement"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($cate);
mysql_free_result($produit);
?>