probleme d affiche d image

john ganzales
Invité n'ayant pas de compte PHPfrance

28 juil. 2014, 17:37

Bonjour
je suis nouveau en php et j ai un probleme d affichage d image avec mon code php, quelqu'un peut il m aider
voici le code
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_data = "localhost";
$database_data = "mbotedb";
$username_data = "root";
$password_data = "";
$data = mysql_pconnect($hostname_data, $username_data, $password_data) or trigger_error(mysql_error(),E_USER_ERROR); 

?>
<?php

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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 "longblob":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";	 
      break;
	  
	  case "longblob":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
	  
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_data, $data);
$sql= mysql_query("SELECT image,image2,image3,image4 FROM images")or die(mysql_error());
	
 // $result = mysql_query("$sql");
  $row_data = mysql_fetch_assoc($sql);
$totalRows_data = mysql_num_rows($sql);



?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<table style="width:99% ;" align="center">
<tr style="background-color:grey";>
    <th>1</th>
    <th>2</th>
    <th>3</th>
    <th>4</th>
  </tr>
  <?php do {  ?>
    <tr>
     <tr>
     <td><?php echo $row_data['image']; ?></td>
     <td><?php echo $row_data['image2']; ?></td>
     <td><?php echo $row_data['image3']; ?></td>
     <td><?php echo $row_data['image4']; ?></td>
    </tr>
    </tr>
    <?php } while ($row_data = mysql_fetch_assoc($sql)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($sql);
?>

et voila ce qu’il donne a l'affichage


Code : Tout sélectionner

ØÿàJFIFddÿìDuckyUÿîAdobedÀÿÛ„ ÿÀ,ôÿļ !1A"Qaq2 ‘B#¡±R3ÁÑb$ðSáñr‚’¢C4% cƒ“56'Td&!1AQaq"‘2ð¡±ÁÑáBR#br’ñ¢34‚ÿÚ?ïå €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P @( €P ž^V%¥¹ê¯µä›ëÊ‚Þÿ2†™ ‰,©RQ}ɏ¬!?â¥OR%BÞ"úTnç`ÚÍXw÷œïþFTŽJÿ(1²+IJN3C ¬uR\˜Ì·”zÝ)ØŸ§J’’|ŒRŠÕ³êïƒÞ–’ÌEËJCÊçéͦYÊ´ÿË67_âSj[º‰£+lµJýÏyç1CS’žµÄX1äòlAi¶Ðw–ã¼…E!+ò…´Tl,AµñÙÇGB_NX×âd¼GîÇËò]«»ôI\)3&Çz4éj_Ü%iuæ[õ–|¨)Yq­Ç®·©ÝuDnÛZ©"ãÃýØ÷5²sîžZƒ8^E;Ègê”!ˆ˜¦Xb"¥*Âçe…ÀfÝ%ª ¹HèþíLÏØ/å¼Ü^c—c9‹aåCȰ¸áIaÕ!·[s×iJu)P^ݪH±ºµÙít¡-«;•S©½|7™aù¶œÎ%`¥Ô%Å5¹*R ð%$‚/Ѝ xuF‹‹£.Õéà €P @( €P @( €P @( €P @( €P @( €P @( €óAaרPRÓtÜÛ]´W€¶r~YŒã)Ü“.ú!ñÜk.KŸ‘pÛL´‚·ŸñÓÃS¥"?tOÜ©¾ääÓÛÞ§ãp7<µzË*“!`).>´¨¥›Ù $¼¨A¨”œß”‘­¼N|snåe9d´üÕ:Úˆq˜zÉBR‘£iC~T¶NÔØ\üI5fݤµ+Ü™cÉò¼>*)›0¤•:†Ðéº[ô’|å²lÑ=/ô½OÁ§­6#¹<žQ5™ÑñÌI!l0ãn)Ç¿^š®n4BE‡‰ ZøN \L£uǸ¾c;۞šìvFYZÔ‡“½Ð…o$*ñ×ë¶~¤ª÷ñ¶•ÆOTL²I+¹ý¾ä®¢'iIާ=e2ì¨N©§A¹Tb¤¤¦ê×ȰG€ÒƼ­Ê<8–azGÀ™ÍÌcÚH\l˜s¨ëZÝÉ2Ñ— J²Â–ärÚö‚R}dŽ¥BúV0¹MxÎ)Ÿo¸]Êíf}Ìò­1— ...
Modifié en dernier par Ryle le 29 juil. 2014, 14:18, modifié 1 fois.
Raison : Mise en forme

ViPHP
xTG
ViPHP | 7331 Messages

28 juil. 2014, 18:17

Tu enregistres donc l'image dans un champ de ta table ?
Si c'est le cas tu ne t'y prend pas du tout comme il faut pour l'afficher.
Il faut injecter en dur le code de l'image tout en changeant le header de la requête pour indiquer que c'est une image.
Ce qui veut dire que tu dois avoir un script à part pour retourner l'image.
Et appeler ce script via une balise img pour chaque image à afficher.
<td><img src="tonScriptPHPAffichageImage.php?image=1" /></td>
<td><img src="tonScriptPHPAffichageImage.php?image=2" /></td>
Un bon exemple ici pour le code PHP :
http://stackoverflow.com/questions/2633 ... ith-header
Sachant que pour ton cas ce n'est pas un readfile puisque tu as déjà le contenu, tu as juste à en faire un echo.

Petit nouveau ! | 4 Messages

31 juil. 2014, 01:29

<td><?php echo $row_data['image']; ?></td>
<td><?php echo $row_data['image2']; ?></td>
<td><?php echo $row_data['image3']; ?></td>
<td><?php echo $row_data['image4']; ?></td>

$row_data doit etre l'url de image :<img src="votre adresse d'image " width="190" height="90" border="0" />