Code: Select all
//save post images
if (isset($_POST['images']))
{
$count = count($_POST['images']);
}
else
{
$count = 0;
}
for ($i=0; $i<$count; $i++)
{
$image_name = $_POST['images'][$i];
$ext = get_ext($image_name );
$uniq = str_replace('.'.$ext, '', $image_name);
$size = filesize(IMG_DIR . $image_name);
//create a thumbnail
$im = imagecreatefromstring(file_get_contents(IMG_DIR . $image_name));
$height = imagesy($im);
$width = imagesx($im);
$im2 = imagecreatetruecolor(THUMB_WID, THUMB_HEI);
imagecopyresampled($im2, $im, 0, 0, 0, 0, THUMB_WID, THUMB_HEI, $width, $height);
$thumb_name = "sm_" . $uniq . '.jpg';
imagejpeg($im2, IMG_DIR . $thumb_name);
//save in DB
$sql = sprintf("INSERT INTO archive_image(archive_id, file, thumb, size, width, height)
VALUES('%s','%s','%s','%s','%s','%s')",
$id, $image_name, $thumb_name, $size, $width, $height);
mysql_query($sql);
}