Witam,

Mam mały hosting obrazków. Kiedy cokolwiek uploaduje - pliki *.jpg - w logach webserwera ukazuje się:
Kod
2013-10-11 16:05:53: (mod_fastcgi.c.2676) FastCGI-stderr: PHP Warning:  imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file
in /var/www/html/remote/thumb.php on line 9
PHP Warning:  imagecreatefromjpeg(): './file/13/10/11//5358045550001.jpg' is not a valid JPEG file in /var/www/html/remote/thumb.php on line 9

2013-10-11 16:05:54: (mod_fastcgi.c.2676) FastCGI-stderr: PHP Warning:  imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file
in /var/www/html/remote/thumb.php on line 9
PHP Warning:  imagecreatefromjpeg(): './file/13/10/11//5358045550001.jpg' is not a valid JPEG file in /var/www/html/remote/thumb.php on line 9

2013-10-11 16:05:55: (mod_fastcgi.c.2676) FastCGI-stderr: PHP Warning:  imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file
in /var/www/html/remote/thumb.php on line 9
PHP Warning:  imagecreatefromjpeg(): './file/13/10/11//5358045550001.jpg' is not a valid JPEG file in /var/www/html/remote/thumb.php on line 9

2013-10-11 16:05:55: (mod_fastcgi.c.2676) FastCGI-stderr: PHP Warning:  imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file
in /var/www/html/remote/thumb.php on line 9
PHP Warning:  imagecreatefromjpeg(): './file/13/10/11//5358045550001.jpg' is not a valid JPEG file in /var/www/html/remote/thumb.php on line 9


plik thumb.php wygląda tak:
Kod
<?php
function createthumb($name,$filename,$new_w,$new_h)
{
    $system = explode('.',$name);
    $system[1] = $system[count($system)-1];
    $system[1] = strtolower($system[1]);
    if(preg_match('/jpg|jpeg/',$system[1]))
    {
        $src_img = imagecreatefromjpeg($name);
    }
    if(preg_match('/png|PNG/',$system[1]))
    {
        $src_img = imagecreatefrompng($name);
    }
    if(preg_match('/gif|GIF/',$system[1]))
    {
        $src_img = imagecreatefromgif($name);
    }

    $old_x = @imageSX($src_img);
    $old_y = @imageSY($src_img);
    if($old_x > $old_y)
    {
        $thumb_w = $new_w;
        $thumb_h = $old_y*($new_h/$old_x);
    }
    if($old_x < $old_y)
    {
        $thumb_w = $old_x*($new_w/$old_y);
        $thumb_h = $new_h;
    }
    if($old_x == $old_y)
    {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    $dist_img = ImageCreateTrueColor($thumb_w,$thumb_h);
    $bg = imagecolorallocate( $dist_img, 255, 255, 255 );
    imagefill ( $dist_img, 0, 0, $bg );
    @imagecopyresampled($dist_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

    if(preg_match('/jpg|jpeg/',$system[1]))
    {
        imagejpeg($dist_img,$filename);
    }
    if(preg_match('/png|PNG/',$system[1]))
    {
        imagepng($dist_img,$filename);
    }
    if(preg_match('/gif|GIF/',$system[1]))
    {
        imagegif($dist_img,$filename);
    }

    @imagedestroy($dist_img);
    @imagedestroy($src_img);

}
?>


Pomimo błędu thumbnail normalnie wychodzi tak jak powinien ale czasem po wrzuceniu nastu plików strona zaczyna zamulać i chodzi niesamowicie wolno
W jaki sposób wyeliminować ten błąd?