Reply to Store image big & thumb in same time

Store image big & thumb in same time new!
by Darwish, 12 years ago
I got a problem to store an image in foreach loop. Sometime image store twice into database.

User upload image & class will given a name to big_image.jpg and thumb_image.jpg. If single upload image it will store correctly to database.

But when multiple image, thumb_ & big_ will stored incorrect into database. Here a part of code for re-size, upload & store into db.
$sort = 1;
foreach ($files as $file) {
  $handle = new Upload($file);
  if ($handle->file_is_image && $handle->image_src_x > 399) {
    if ($handle->uploaded) {
      $handle->image_watermark = IMAGES . 'watermark.png';
      $handle->image_watermark_position = 'TBLR';
      $handle->jpeg_quality             = 75;
      $handle->image_convert            = 'jpg';
      $big                              = $handle->file_new_name_body = 'big_' . time();
      if ($handle->image_src_x > 772) {
        $handle->image_resize             = true;
        $handle->image_ratio_y            = true;
        $handle->image_x                  = 773;
      }
      $handle->Process($dir_dest);
      $big_width = $handle->image_dst_x;
      $big_height = $handle->image_dst_y;							
                
      // create thumbnail
      $handle->jpeg_quality     = 75;
      $handle->image_convert    = 'jpg';
      $thumb                    = $handle->file_new_name_body = 'thumb_' . time();
      $handle->image_resize     = true;
      $handle->image_ratio_crop = true;
      $handle->image_x          = 100;
      $handle->image_y          = 100;
      $handle->Process($dir_dest);
                
      $db->query("INSERT INTO ads_images SET
                        img_aid = '" . (int) $ad_id . "',
                        img_uid = '" . (int) $user->user_id . "',
                        img_big = '" . $db->escape($big) . ".jpg',
                        img_bigx = '" . (int)$big_width . "',
                        img_bigy = '" . (int)$big_height . "',
                        img_thumb = '" . $db->escape($thumb) . ".jpg',
                        img_sort = '" . (int) $sort . "'
                    ");
      $sort++;
      $handle->Clean();
    }
  }
}

May I know a mistake hereReply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important