Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Upload image and create thumbnail


matthewamzn - 11:22 pm on Sep 21, 2008 (gmt 0)


I'm trying to upload an image and it's thumbnail to my database. I'm stuck on resizing the image. This successfully uploads an image, but the resize fails.

$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"),
$_FILES['file']['size']));

$thumb = imagecreatefromstring($photo);
$width = imagesx($thumb);
$height = imagesy($thumb);
$thumb_height = 100;
$thumb_width = $width / $height * $thumb_height;
$thumbnail = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumbnail,$thumb,0,0,0,0,$width,$height,ImageSX($thumb),ImageSY($thumb));

$vehicle_id = $_POST['vehicle_id'];
$query = sprintf("INSERT INTO v_images(photo, file_ype, vehicle_id, thumbnail) VALUES
('%s', '%s', '%s', '%s')", $photo, $_FILES['file']['type'], $vehicle_id, $thumbnail);


Thread source:: http://www.webmasterworld.com/php/3749240.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com