probleme affichage image

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : probleme affichage image

re

par adel » 27 mai 2007, 21:32

je t'envoie mon code
par quoi je peut remplacer header
merci de ton aide
<html>
<head>
<title>Stock d'images</title>
</head>
<body>
<?
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'];
$hote = 'localhost';
$base = 'test';
$user = 'pol';
$pass = 'polo';
$cnx = mysql_connect ($hote, $user, $pass) or die (mysql_error ());
$ret = mysql_select_db ($base) or die (mysql_error ());
$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."', ".
// N'oublions pas d'échapper le contenu binaire
"'".addslashes ($img_blob)."') ";
$ret = mysql_query ($req) or die (mysql_error ());
return true;
}
}

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>

Ensuite la page liste :
<html>
<head><title>Liste d'images</title></head>
<body>
<?
$hote = 'localhost';
$base = 'test';
$user = 'pol';
$pass = 'polo';
$cnx = mysql_connect ($hote, $user, $pass) or die (mysql_error ());
$ret = mysql_select_db ($base) or die (mysql_error ());
$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>

Et maintenant la page apercu.php
<?
if ( isset($_GET['id']) )
{
$id = intval ($_GET['id']);
$hote = 'localhost';
$base = 'test';
$user = 'pol';
$pass = 'polo';
$cnx = mysql_connect ($hote, $user, $pass) or die (mysql_error ());
$ret = mysql_select_db ($base) or die (mysql_error ());
$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";
}
?>

par titerm » 27 mai 2007, 20:46

Dans ton message d'erreur, il est dit que tu as déjà envoyé des caractères en ligne 3. Tu ne peux donc plus utiliser la fonction header(). Regarde au début de ton script, tu as certainement des espaces ou des caratères qui trainent avant le '<?php'

probleme affichage image

par adel » 27 mai 2007, 20:21

bonjour
je ne comprend pas pourquoi au lieu d'afficher une image se ne sont que des code

de plus on m'envoie ce mesage
aide svp
merci

Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\apercu.php:3) in c:\program files\easyphp1-8\www\apercu.php on line 23
<?php
if ( isset($_GET['id']) )
{
$id = intval ($_GET['id']);
$hote = 'localhost';
$base = 'test';
$user = 'pol';
$pass = 'polo';
$cnx = mysql_connect ($hote, $user, $pass) or die (mysql_error ());
$ret = mysql_select_db ($base) or die (mysql_error ());
$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[2]);
echo $col[2];
}
}
else
{
echo "Mauvais id d'image";
}
?>