begin process at 2010 03 21 12:18:06
  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

image et GD [ par papipsycho ] salut a tous voila jai un pb donc jai un script qui marche tres bien pour cree des image et prendre des inf dans ma BDD(un script que jai recupere ici MySql, image et tableau [ par BirD ] Hello tout le monde, g un ptit problème:j'ai une base de donnée mysql qui contient le chemin de mon image sur le site, et depuis ma page, j'aimerais a MySQL et images [ par Marneus Calgar ] SalutJ'aimerais savoir s'il est possible de stocker des images dans une table MySQL et d'y accéder depuis une page PHP. En fait, je voudrais faire un MySQL et images [ par Marneus Calgar ] SalutJ'aimerais savoir s'il est possible de stocker des images dans une table MySQL et d'y accéder depuis une page PHP. En fait, je voudrais faire un image php Mysql [ par arnaldo21 ] bonjour pourriez-vous me donner un exemple concret d'affichage d'image a partir d'une bdd. J'utilise un upload qui stock le nom de l'image dans la bdd php/mysql et album photo sécurisé [ par pumbaa ] Salut!!   J’ai crée un album d’image avec php/MySQL. Les images ce trouvent image directement dans mysql [ par speedylol ] bonsoir j aimerais savoir comment envoyez une image directement dams ma base de donnée svp.Je vous remerci de renseignement. encore un prob easyphp 1.6 - 1.7 [ par Pretender ] Salut,donc jai installé easyphp1.7 et le problème que j'ai maintenant est que:j'ai le code suivant:< Liaisons image et commentaires dans mysql [ par piballo ] Bonjours j'aurai besoin pour mon site d'uploader et lier des image et commentaire dans une table mysql depuis le backoffice de mon site.Malheureusemen problème de moteur de recherche [ par oceane751 ] bonsoir à tous!! j'essaye de creer un petit moteur de recherche sur mon site mais je rencontre quelque problème, je n'arrive pas à afficher les donnée


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mars 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

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 : 0,437 sec (4)

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