2014-09-10 51 views
0

顯示多個圖像BLOB我應該表現出從MySQL數據庫中的一些BLOB的圖像,此PHP代碼:問題從MySQL

<?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; 
?> 

任何線索?非常感謝你。

回答

1

可能是內存問題 - 分配內存以在刷新時創建每個映像......這是一個完全不好的做法。

您可以嘗試將圖像保存在某處或至少緩存它們,以便您不必在每次刷新時使用創建圖像的所有過程。

+0

沒錯。保存斑點圖像是一個非常糟糕的做法,必須避免。 – 2015-05-13 11:17:38