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
include('lib/class.upload.php'); $file = "image.jpg"; $files = "new-image.jpg"; $handle = new upload($file); if ($handle->uploaded) { $handle->file_new_name_body = $files; $handle->image_resize = true; $handle->image_y = 400; $handle->image_ratio_x = true; header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($files)); echo $handle->process(); die(); } else { echo 'error : ' . $handle->error; }