[英]Problems displaying several BLOB images from MySQL
我有這個PHP代碼,應該顯示來自MySQL數據庫的一些BLOB圖像:
<?php
while ($articulo = mysql_fetch_array($resultados))
{
?>
<div class="categoria">
<a href="catalogo.php?categoria_serial=<?php echo $articulo['categoria_serial'];?>">
<img src="imagenCategoria.php?categoria_serial=<?php echo $articulo['categoria_serial'];?>&ancho=280" alt="">
</a>
<div class="descripcion">
<p><?php echo $articulo['categoria_nombre'];?></p>
</div>
</div>
<?php
}
?>
問題是,並非每個圖像都顯示在頁面中。 有些圖像隨機不加載。 如果刷新頁面,則會出現一些丟失的圖像,但是一些正確的圖像會消失。
這是每個圖像的代碼:
<?php
include 'controller/_init.php';
$db = conectar();
$desired_width = $_GET["ancho"];;
$categoria_serial = $_GET["categoria_serial"];
$resultados = mysql_query("SELECT categoria_imagen FROM categoria WHERE categoria_serial = $categoria_serial") or die("Error");
$articulo=mysql_fetch_array($resultados);
$im = imagecreatefromstring($articulo['categoria_imagen']);
$x = imagesx($im);
$y = imagesy($im);
$desired_height = $desired_width*$y/$x;
$new = imagecreatetruecolor($desired_width, $desired_height);
imagecopyresampled($new, $im, 0, 0, 0, 0, $desired_width,$desired_height, $x, $y);
imagedestroy($im);
header('Content-type: image/jpeg');
imagejpeg($new, null, 85);
exit;
?>
有什么線索嗎? 非常感謝你。
可能是內存問題-在刷新時分配用於創建每個圖像的內存...這是完全不正確的做法。
您可以嘗試將圖像保存在某處或至少將其緩存,這樣就不必在每次刷新時都使用創建圖像的所有過程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.