Page 1 sur 1

re probleme de recuperation d'image sur base de donnees

Posté : 26 mai 2007, 14:53
par adel
bonjour

je ne comprend pas ou est l'erreur


<?
<!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">
<html>
<head>
<title>Stock d'images</title>
</head>
<body>
<?
include ("transfert.php");
if ( isset($_FILES['fic']) )
{
transfert();
}
?>
<h3>Envoi d'une image</h3>
<form enctype="multipart/form-data" action="#" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="250000" />
<input type="file" name="fic" size=50 />
<input type="submit" value="Envoyer" />
</form>
<p><a href="liste.php">Liste</a></p>
</body>
</html>

<html>
______________________________________________fichier transfert___________________________________________________
<?
function transfert ()
{
$ret = false;
$img_blob = '';
$img_taille = 0;
$img_type = '';
$img_nom = '';
$taille_max = 250000;
$ret = is_uploaded_file ($_FILES['fic']['tmp_name']);
if ( !$ret )
{
echo "Problème de transfert";
return false;
}
else
{
// Le fichier a bien été reçu
$img_taille = $_FILES['fic']['size'];
if ( $img_taille > $taille_max )
{
echo "Trop gros !";
return false;
}
$img_type = $_FILES['fic']['type'];
$img_nom = $_FILES['fic']['name'];
include ("connexion.php");
$img_blob = file_get_contents ($_FILES['fic']['tmp_name']);
$req = "INSERT INTO images (".
"img_nom, img_taille, img_type, img_blob ".
") VALUES (".
"'".$img_nom."', ".
"'".$img_taille."', ".
"'".$img_type."', ".
"'".$img_blob."') ";
"'".addslashes ($img_blob)."') ";
$ret = mysql_query ($req) or die (mysql_error ());
return true;
}
}



?>
</html>

____________________fichier connextion______________________________________________
<html>
<?
$hote = 'localhost';
$base = 'test';
$user = 'root';
$pass = '';
$cnx = mysql_connect ($hote, $user, $pass) or die (mysql_error ());
$ret = mysql_select_db ($base) or die (mysql_error ());

?>


</html>
___________________________________fichier liste.php___________

!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><title>Stock d'images</title></head>
<body>
<?php
include ("connexion.php");
$req = "SELECT img_nom, img_id ".
"FROM images ORDER BY img_nom";
$ret = mysql_query ($req) or die (mysql_error ());
while ( $col = mysql_fetch_row ($ret) )
{
echo "<a href=\"apercu.php?id=".$col[1].
"\">".$col[0]."</a><br />";
}
?>
</body>
</html>


____________________________________fichier apercu.php________________
<html>

<?php
if ( isset($_GET['id']) )
{
$id = intval ($_GET['id']);
include ("connexion.php");
$req = "SELECT img_id, img_type, img_blob ".
"FROM images WHERE img_id = ".$id;
$ret = mysql_query ($req) or die (mysql_error ());
$col = mysql_fetch_row ($ret);
if ( !$col[0] )
{
echo "Id d'image inconnu";
}
else
{
header ("Content-type: ".$col[1]);
echo $col[2];
}
}
else
{
echo "Mauvais id d'image";
}
?>
</html>
?>

Posté : 26 mai 2007, 14:59
par Sékiltoyai
1) Les balises php ou code s'il te plait.
2) Sans message d'erreur ou autre explication, nous non plus, nous ne comprenons pas d'où vient l'erreur...

Posté : 26 mai 2007, 15:31
par Cyrano
Les balises php ou code s'il te plait....
D'autant que tu as déjà été averti !

Re: re probleme de recuperation d'image sur base de donnees

Posté : 26 mai 2007, 17:17
par Invité
[quote="adel"]bonjour

je ne comprend pas ou est l'erreur

<!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">
<html>
<head>
<title>Stock d'images</title>
</head>
<body>
<?
include ("transfert.php");
if ( isset($_FILES['fic']) )
{
transfert();
}
?>
<h3>Envoi d'une image</h3>
<form enctype="multipart/form-data" action="#" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="250000" />
<input type="file" name="fic" size=50 />
<input type="submit" value="Envoyer" />
</form>
<p><a href="liste.php">Liste</a></p>
</body>
</html>

<html>
______________________________________________fichier transfert___________________________________________________
<?
function transfert ()
{
$ret = false;
$img_blob = '';
$img_taille = 0;
$img_type = '';
$img_nom = '';
$taille_max = 250000;
$ret = is_uploaded_file ($_FILES['fic']['tmp_name']);
if ( !$ret )
{
echo "Problème de transfert";
return false;
}
else
{
// Le fichier a bien été reçu
$img_taille = $_FILES['fic']['size'];
if ( $img_taille > $taille_max )
{
echo "Trop gros !";
return false;
}
$img_type = $_FILES['fic']['type'];
$img_nom = $_FILES['fic']['name'];
include ("connexion.php");
$img_blob = file_get_contents ($_FILES['fic']['tmp_name']);
$req = "INSERT INTO images (".
"img_nom, img_taille, img_type, img_blob ".
") VALUES (".
"'".$img_nom."', ".
"'".$img_taille."', ".
"'".$img_type."', ".
"'".$img_blob."') ";
"'".addslashes ($img_blob)."') ";
$ret = mysql_query ($req) or die (mysql_error ());
return true;
}
}



?>
</html>

____________________fichier connextion______________________________________________
<html>
<?
$hote = 'localhost';
$base = 'test';
$user = 'root';
$pass = '';
$cnx = mysql_connect ($hote, $user, $pass) or die (mysql_error ());
$ret = mysql_select_db ($base) or die (mysql_error ());

?>


</html>
___________________________________fichier liste.php___________

!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><title>Stock d'images</title></head>
<body>
<?php
include ("connexion.php");
$req = "SELECT img_nom, img_id ".
"FROM images ORDER BY img_nom";
$ret = mysql_query ($req) or die (mysql_error ());
while ( $col = mysql_fetch_row ($ret) )
{
echo "<a href="apercu.php?id=".$col[1].
"">".$col[0]."</a><br />";
}
?>
</body>
</html>


____________________________________fichier apercu.php________________
<html>

<?php
if ( isset($_GET['id']) )
{
$id = intval ($_GET['id']);
include ("connexion.php");
$req = "SELECT img_id, img_type, img_blob ".
"FROM images WHERE img_id = ".$id;
$ret = mysql_query ($req) or die (mysql_error ());
$col = mysql_fetch_row ($ret);
if ( !$col[0] )
{
echo "Id d'image inconnu";
}
else
{
header ("Content-type: ".$col[1]);
echo $col[2];
}
}
else
{
echo "Mauvais id d'image";
}
?>
</html>
?>

Re: re probleme de recuperation d'image sur base de donnees

Posté : 26 mai 2007, 17:37
par Cyrano
...je ne comprend pas ou est l'erreur
Quelle erreur au juste ?

Posté : 26 mai 2007, 18:37
par adel
quand je lance le fichier index.php et que j'appuie sur le lien liste je recois ceci
j'ai tout essaiye mais sa bloque
Warning: main(connexion.php): failed to open stream: No such file or directory in c:\program files\easyphp1-8\www\envoi recp base image\liste.php on line 8

Warning: main(): Failed opening 'connexion.php' for inclusion (include_path='.;C:/Program Files/EasyPHP1-8\php\pear\') in c:\program files\easyphp1-8\www\envoi recp base image\liste.php on line 8

Warning: mysql_query(): Accès refusé pour l'utilisateur: 'ODBC'@'@localhost' (mot de passe: NON) in c:\program files\easyphp1-8\www\envoi recp base image\liste.php on line 11

Warning: mysql_query(): A link to the server could not be established in c:\program files\easyphp1-8\www\envoi recp base image\liste.php on line 11
Accès refusé pour l'utilisateur: 'ODBC'@'@localhost' (mot de passe: NON)

Posté : 26 mai 2007, 21:57
par Cyrano
Ça veut dire que le fichier connexion.php n'est pas là où il est attendu : vérifie ton code et si tu as bien mis le bon chemin vers ce fichier.