begin process at 2012 02 12 20:53:22
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Archive PHP

 > 

Archives

 > 

Débutants

 > 

upload image


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

upload image

dimanche 22 janvier 2006 à 19:06:30 | upload image

tomm123456

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">&nbsp;</td>
      <td><input type="submit" value="Insérer l'enregistrement"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($cate);
mysql_free_result($produit);
?>


lundi 23 janvier 2006 à 10:19:48 | Re : upload image

malalam

Administrateur CodeS-SourceS
Hello,

dis nous plutôt quelle erreur tu as. Parce que là, je n'ai rien compris à ton problème.
lundi 23 janvier 2006 à 10:24:08 | Re : upload image

tomm123456

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
lundi 23 janvier 2006 à 18:03:49 | Re : upload image

tomm123456

j'ai trouvé
voilà le code
<?php require_once('../Connections/conn.php');
//images

if( isset($_POST['Submit']) and $_FILES['photo_produit']['name']!="")
 
{
    $size = 150; // the thumbnail weight

    $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[0]/$sizes[1]; //le 0 largeur 1 hauteur

        if ($sizes[0] <= $size)
        {
            $new_width = $sizes[0];
            $new_height = $sizes[1];
        }else{
            $new_width = $size;
            $new_height = abs($new_width/$aspect_ratio); //abs (absolu) car pixel doit valeur entiere
        }

        $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);
    }

   

}  else $userfile_name = "visuelnondisponible.jpg";

//bases
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($userfile_name, "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 id_categorie, nom_categorie 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_prod = "SELECT * FROM produits";
$prod = mysql_query($query_prod, $conn) or die(mysql_error());
$row_prod = mysql_fetch_assoc($prod);
$totalRows_prod = mysql_num_rows($prod);


?>
<link href="../style.css" rel="stylesheet" type="text/css" />

    <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" >
      <div align="center">
        <table width="498" border="0" cellspacing="5" cellpadding="0">
          <tr>
            <td colspan="2"><div align="center" class="titre">Ajout d'un article </div></td>
          </tr>
          <tr>
            <td width="158"><div align="center">nom du produit </div></td>
            <td width="325"><div align="center">
              <p align="left">
                <input name="nom_produit" type="text" id="nom_produit" size="32" />
                <br />
              </p>
              </div></td>
          </tr>
          <tr>
            <td><div align="center">Description du produit </div></td>
            <td>
              <div align="left">
                <textarea name="description_produit" cols="50" rows="5" id="description_produit"></textarea>
                </div></td></tr>
          <tr>
            <td><div align="center">Photo du produit </div></td>
            <td>
              <div align="left">
                <input type="file" name="photo_produit" value="" />           
                </div></td></tr>
          <tr>
            <td><div align="center">Cat&eacute;gorie du produit </div></td>
            <td>
              <div align="left">
                <select name="categorie_produit" id="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>
                  </div></td></tr>
          <tr>
            <td>&nbsp;</td>
            <td>
              <div align="left">
                <input type="submit" name="Submit" value="Ajouter l' article" />             
                </div></td></tr>
        </table>
        <BR >
      </div>
      <p>
        <input type="hidden" name="MM_insert" value="form1">
    </form>





    <div align="center">
      <?php
mysql_free_result($cate);

mysql_free_result($prod);
?>
      <table width="324" height="111" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="324"><p class="texteencadre">Pour ajouter une photo au format jpeg (uniquement ) , sans d&eacute;passer un format de 500 pixels par 500 pixels , cliquer sur parcourir puis s&eacute;lectionner votre image sur le disque dur et cliquer sur ouvrir .Ensuite remplisser le formulaire normalement et ajouter l'article . </p>
            <p class="texteencadre">Si vous souhaitez modifer votre image prise avec un appareil photo ,utliser adobe photoshop ou Gimp(gratuit) pour redimensionner votre image et la compressser sans d&eacute;passer 500 pixels par 500 pixels. </p>
            <p align="center"><a href="index.php">Retour administration du site</a></p></td>
        </tr>
      </table>
    </div>
   



Cette discussion est classée dans : mysql, image, produit, thevalue, cate


Répondre à ce message

Sujets en rapport avec ce message

importation excel mysql [ par mohamedinfo ] Bonjour, J'ai un fichier excel 2007/2003 qui contient 3 colonnes (code du produit,nom du produit et l'image du produit sockée par copié collé dans la galerie photo avec php [ par stophking ] bonjour : je suis entrain de créer une galerie photo avec php/mysql et j'aimeria bien que vous me corriger le code si il ya des fautes, et une chose q upload une image + envoi de donnees [ par gobgob74 ] bonjour,j'ai vraiment besoin qu'un grand dévellopeur php m'aide.mon probleme est que j'au creer un jeu d'enregistrement grace a dreamweaver et dans mo Image / MySQL / php [ par hazkaal ] Bonjour !Je bosse sur un site et j'ai un probleme au niveau de laffichage d'images...Je m'explique :L'utilisateur upload une image. Cette image est st Une police de caractere dans un image [ par momosan77 ] Bonjour, je suis actuellement sur la modification d'un code ou je dois modifier la taille ou sa police de caractère des teste sur l'image crée. Donc Probleme lors d'un upload [ par voyager ] Bonjour Ci-dessous ma démarche bon je suis débutant mais je me soigne, mais dans le cas présent après de nombreux essais je reste bloque 1) Upload inserer le contenu d'un textarea dans une base de données [ par patingfree ] Bonjour à tous, J'ai 3 mois d'expérience en php et suis confronté à un problème. Je dispose d'un formulaire (produit) et un fichier d'envoie du formul mysql et javascript [ par sherifff ] Bonjour Actuellement j'ai le script suivant "javascript" dans un fichier js: window.addEvent('domready', function(){ var data = { 'image Stocker une image dans mysql [ par ewertheimer ] Bonjour,Pourriez vous m'aider sur la maniere dont je dois proceder pour stocker des images dans une base mysql. Je ne l'ai encore jamais fait je n'ai apeller du html stocke dans mysql avec du php flah et image [ par fantomas3800 ] Bonjour bonjour,grande debutante en php, j essaye de creer un site .. et ca y est je butte encore .... Si qq un peu me donner un coup de main ca serai


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 3,994 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales