Upload image

tomm123456 Messages postés 52 Date d'inscription jeudi 8 décembre 2005 Statut Membre Dernière intervention 11 avril 2007 - 22 janv. 2006 à 19:06
tomm123456 Messages postés 52 Date d'inscription jeudi 8 décembre 2005 Statut Membre Dernière intervention 11 avril 2007 - 23 janv. 2006 à 18:03
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>





<form method="post" name="form1" action="" enctype="multipart/form-data">

Nom_produit:,

,

----

Description_produit:,

<textarea name="description_produit" cols="50" rows="5"></textarea>,

----

Photo_produit:,

,

----

Categorie_produit:,

<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>,

----

&nbsp;,




</form>

&nbsp;




</html>

<?php

mysql_free_result($cate);

mysql_free_result($produit);

?>

3 réponses

malalam Messages postés 10839 Date d'inscription lundi 24 février 2003 Statut Membre Dernière intervention 2 mars 2010 25
23 janv. 2006 à 10:19
Hello,

dis nous plutôt quelle erreur tu as. Parce que là, je n'ai rien compris à ton problème.
0
tomm123456 Messages postés 52 Date d'inscription jeudi 8 décembre 2005 Statut Membre Dernière intervention 11 avril 2007
23 janv. 2006 à 10:24
J'ai un forumalire d'insertion dans une base avec un upload d'image qui sera envoyé dans 2 repertoire differents : une petite et un egrande.La table se remplie bien avec le nom de la photo mais l'upload ne se fait pas.Je n'ai aucun message d'erreur
0
tomm123456 Messages postés 52 Date d'inscription jeudi 8 décembre 2005 Statut Membre Dernière intervention 11 avril 2007
23 janv. 2006 à 18:03
j'ai trouvé

voilà le code







0
Rejoignez-nous