probleme d`insertion de l`url de l`image apres son upload

martin266
Nouveau WRInaute
Nouveau WRInaute
 
Messages: 3
Inscription: 22 Aoû 2008

probleme d`insertion de l`url de l`image apres son upload

Message le Mar Aoû 26, 2008 19:30

bonjour,
j`arrive a bien apploader l`image sur le serveur mais quand je les stocke dans la BD, tous les champs de la table s`ajoutent sauf le champ chemin ou je dois stocker le chemin de l`image.
je comprend pas exactement pk ca marche pas.

Code: Tout sélectionner
      index.php:
<?php

// filename: upload.form.php




$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);


$uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'add_image.php';


$max_file_size = 30000; // size in bytes


?>

<html lang="en">
   <head>
      <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
   
      <link rel="stylesheet" type="text/css" href="stylesheet.css">
      
      <title>Upload form</title>
   
   </head>
   
   <body>
   
   <form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">
   
   <table border="0" align="center" cellspacing="2" cellpadding="2">

<tr align="center">
      <td> <b> reference de produit </b> </td>
      <td><input type="text" name="ref_produit"></td>
    </tr>

<tr align="center">
      <td> <b> titre du produit </b> </td>
      <td><input type="text" name="titre"></td>
    </tr>

<tr align="center">
      <td> <b> description </b> </td>
      <td><input type="text" name="description"></td>
    </tr>
   
<tr align="center">
      <td> <b> prix </b> </td>
      <td><input type="text" name="prix"></td>
    </tr>
   
  <tr align="center">
      <td> <b> date d`ajout </b> </td>
      <td><input type="text" name="date_ajout"></td>
    </tr>
   
   
   <tr align="center">
      <td> <b> reference de type </b> </td>
      <td><input type="text" name="ref_type"></td>
    </tr>
   
   <tr align="center">
      <td> <b> reference de l`artiste </b> </td>
      <td><input type="text" name="ref_artiste"></td>
    </tr>
   
   
    <tr align="center">
      <td> <b> image </b> </td>
      <td><input type="file" name="chemin" size=50></td>
    </tr>
   
   
   <tr align="center">
      <td colspan="2"><input type="submit" name="submit" value="ajouter"></td>
     
    </tr>
   
</table>

       
</form>
   
   
   </body>

</html>


Code: Tout sélectionner
      add_image.php:
<html >
<head>
<title>Document sans titre</title>
</head>
<body>

<?php 
$db =  mysql_connect("localhost","root","");    // connexion a la base de donnee
mysql_select_db("boutique",$db);               // selection de la base de donnee

   $ref_produit = $_POST["ref_produit"] ;
 
   $titre = $_POST["titre"] ;
 
   $description = $_POST["description"] ;
   
   $prix = $_POST["prix"] ;
   
   $date_ajout = $_POST["date_ajout"] ;
   
   $chemin = $_POST["chemin"] ;
   
   $ref_type = $_POST["ref_type"] ;
   
   $ref_artiste = $_POST["ref_artiste"] ;


création de la requête SQL:
  $sql = "INSERT  INTO produit ( ref_produit, titre, description, prix, date_ajout, chemin, ref_type, ref_artiste)
            VALUES ('$ref_produit', '$titre', '$description', '$prix', '$date_ajout','$chemin', '$ref_type', '$ref_artiste') " ;

             
exécution de la requête SQL:
  $requete = mysql_query($sql, $db) or die( mysql_error() ) ;



$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);


$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'images/';
chmod ($uploadsDirectory, 0644);

$uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'index18.php';


$uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.success.php';


$fieldname = 'chemin';



$errors = array(1 => 'php.ini max file size exceeded',
                2 => 'html form max file size exceeded',
                3 => 'file upload was only partial',
                4 => 'no file was attached');


isset($_POST['submit'])
    or error('the upload form is neaded', $uploadForm);


($_FILES[$fieldname]['error'] == 0)
    or error($errors[$_FILES[$fieldname]['error']], $uploadForm);
   

@is_uploaded_file($_FILES[$fieldname]['tmp_name'])
    or error('not an HTTP upload', $uploadForm);
   

@getimagesize($_FILES[$fieldname]['tmp_name'])
    or error('only image uploads are allowed', $uploadForm);
   

$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
{
    $now++;
}


@move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
    or error('receiving directory insuffiecient permission', $uploadForm);
   
//exécution de la requête SQL:
  $requete = mysql_query($sql, $db) or die( mysql_error() ) ;
header('Location: ' . $uploadSuccess);

// make an error handler which will be used if the upload fails
function error($error, $location, $seconds = 5)
{
    header("Refresh: $seconds; URL=\"$location\"");
    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
    '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
    '<html lang="en">'."\n".
    '    <head>'."\n".
    '        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
    '        <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
    '    <title>Upload error</title>'."\n\n".
    '    </head>'."\n\n".
    '    <body>'."\n\n".
    '    <div id="Upload">'."\n\n".
    '        <h1>Upload failure</h1>'."\n\n".
    '        <p>An error has occured: '."\n\n".
    '        <span class="red">' . $error . '...</span>'."\n\n".
    '         The upload form is reloading</p>'."\n\n".
    '     </div>'."\n\n".
    '</html>';
    exit;
}

// end error handler
?>

</body>
</html>


jai un autre fichier.php, mais c just pour afficher le succes de l`upload.

merci beaucoup d`avance, s`il ya qlq1 qui peut me dire pourkoi le champ chemin s`ajoute pas dans la base de donnee

Si vous avez aimé cette discussion, partagez-la sur vos réseaux sociaux préférés :

Lectures recommandées sur ce thème :

Consultez la description détaillée des produits ou services de Google suivants : Google Video Upload

  • Analyse de popularité
    Cet outil vous permet d'analyser en détails la "popularité" de votre site sur Google. En plus du nombre de liens pris en compte par Google, il calcule le pourcentage de liens internes parmi tous les liens, et il affiche les premières URL trouvées.


Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 1 invité