php - Getting error while uploading some selected images -


i have following php code uploading images on website.

//codes

global $objdb;  global $path_to_image_directory ;   global $path_to_thumbs_directory ;  $final_width_of_image = 500;    $path_to_image_directory =  'uploads/fullsized/';    $path_to_thumbs_directory = 'uploads/thumbs/';   $imagetitle="";  $mysqli = $objdb->connection;   if(isset($_files['uploaded']['name'])) {   if(preg_match('/[.](jpg)|(gif)|(png)$/', $_files['uploaded']['name'])) {        $filename = $_files['uploaded']['name'];       $source = $_files['uploaded']['tmp_name'];       $target = $path_to_image_directory . $filename;        move_uploaded_file($source, $target);        createthumbnail($filename);          $sql="insert gallery(image)values('$filename')";     $result=$objdb->query($sql);       if($result==1)     {     header("location:gallery.php?s_msg=image added gallery");     }     else     {       header("location:gallery.php?f_msg=unable add image");     }        }   else     {       header("location:gallery.php?f_msg=unable add image");     }    }  else     {       header("location:gallery.php?f_msg=unable add image");     }           function createthumbnail($filename) {        $path_to_image_directory="";  $path_to_thumbs_directory="";  $final_width_of_image="";  $path_to_image_directory =  'uploads/fullsized/';        $path_to_thumbs_directory = 'uploads/thumbs/';  $final_width_of_image = 400;   if(preg_match('/[.](jpg)$/', $filename)) {      $im = imagecreatefromjpeg($path_to_image_directory . $filename);    } else if (preg_match('/[.](gif)$/', $filename)) {       $im = imagecreatefromgif($path_to_image_directory . $filename);   } else if (preg_match('/[.](png)$/', $filename)) {       $im = imagecreatefrompng($path_to_image_directory . $filename);   }      $ox = imagesx($im);    $oy = imagesy($im);      $nx = $final_width_of_image;   $ny = floor($oy * ($final_width_of_image / $ox));    $nm = imagecreatetruecolor($nx, $ny);    imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);    if(!file_exists($path_to_thumbs_directory)) {     if(!mkdir($path_to_thumbs_directory)) {          die("there problem. please try again!");     }       }    imagejpeg($nm, $path_to_thumbs_directory . $filename);    }    

everything working fine till yesterday, when user tried upload image of size 1mb

and throwing error :

premature end of jpeg file in db_gallery.php on line 64  fullsized/the_amazing_spider_man_2_movie-2048x1536.jpg' not valid jpeg file. 

the image uploaded server thumbnail not created, pls help.

please try upload "gif" or "png" image , check throws same error !


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -