par
alex288 » 13 août 2008, 16:28
je suis tjrs en train dinserer une image dans mysql, ca se upload tres bien dans le serveur, mais son chemin et les autres champs du formulaire s`ajoutent pas dans la base de donnee.
voila mon formulaire:
<?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>
et mon fichier php:
<html >
<head>
<title>Document sans titre</title>
</head>
<body>
<?php
mysql_connect("localhost","root",""); // connexion a la base de donnee
mysql_select_db("produit"); // 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["image"] ;
$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, image, ref_type, ref_artiste)
VALUES ('$ref_produit', '$titre', '$description', '$prix', '$date_ajout','$chemin', '$ref_type', '$ref_artiste') " ;
$result = mysql_query($sql);
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'images/';
$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);
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 ca sert just pour afficher un message de felicitations de lupload.
s`il ya qlq 1 qui m`indiquer pourkoi j`arrive pas a inserer les donnees dans la base de donnee
merci beaucoup
en fait je suis arrive a inserer tt les champs dans la base de donnee saut le champ chemin ou je stocke le chemin de l`image qui reste vide.
je serais tres reconnaissant de votre aide
je suis tjrs en train dinserer une image dans mysql, ca se upload tres bien dans le serveur, mais son chemin et les autres champs du formulaire s`ajoutent pas dans la base de donnee.
voila mon formulaire:
[php]<?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>[/php]
et mon fichier php:
[php]
<html >
<head>
<title>Document sans titre</title>
</head>
<body>
<?php
mysql_connect("localhost","root",""); // connexion a la base de donnee
mysql_select_db("produit"); // 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["image"] ;
$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, image, ref_type, ref_artiste)
VALUES ('$ref_produit', '$titre', '$description', '$prix', '$date_ajout','$chemin', '$ref_type', '$ref_artiste') " ;
$result = mysql_query($sql);
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'images/';
$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);
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>[/php]
jai un autre fichier php mais ca sert just pour afficher un message de felicitations de lupload.
s`il ya qlq 1 qui m`indiquer pourkoi j`arrive pas a inserer les donnees dans la base de donnee
merci beaucoup
en fait je suis arrive a inserer tt les champs dans la base de donnee saut le champ chemin ou je stocke le chemin de l`image qui reste vide.
je serais tres reconnaissant de votre aide