class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
more info about the class
$handle = new upload($_FILES['photo']); if ($handle->uploaded) { $handle->file_new_name_body = $filename; $handle->file_auto_rename = true; $handle->image_resize = true; $handle->image_x = 400; $handle->image_y = 400; $handle->image_ratio = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = 95; $handle->process('../../../gallery/photos'); $handle->file_new_name_body = $filename . "_thumb"; $handle->file_auto_rename = true; $handle->image_resize = true; $handle->image_x = 120; $handle->image_y = 120; $handle->image_ratio = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = 95; $handle->process('../../../gallery/photos/thumbs'); if ($handle->processed) { $photo = $handle->file_dst_name_body; $handle->clean(); $addPhotoSql = "INSERT INTO images (caption, filename, album) VALUES ('$caption', '$photo', '$albumTitle')"; $addPhoto = mysql_query($addPhotoSql) or die(mysql_error()); header('Location: display_album.php?album=' . $url . "#thumbs"); } else { echo 'error : ' . $handle->error; } } }