0

I have this PHP code supposed to show some BLOB images from a MySQL database:

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

The problem is, not every image is shown in the page. Some of the images randomly don't load. If I refresh the page, some of the missing images appear, but some of the correct images dissapear.

Here's the code for every image:

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

Any clue? Thank you very much.

1 Answer 1

1

Could be a memory problem - allocating memory for creating each image on refresh... that is a totally bad practice.

You may try saving the images somewhere or at least caching them, so that you don't have to use all the procedure of creating image on each refresh.

Sign up to request clarification or add additional context in comments.

1 Comment

That's right. Saving blob images is a very bad practice that must be avoided.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.