Resize image on upload

This code displays a form that the user can use to resize an image on upload. When the form is submitted the image is uploaded to a tempory location where it is then resized and saved into the directory set in the code.

Note: If allowing user uploads the data submitted MUST be checked to stop people uploading code that can compramise the server.

// If the form has been submitted do this
if ( isset( $_POST['Submit'] ) ){

// Temporary upload image name
$original_image $_FILES['filename']['tmp_name'];

// Get the image dimensions
$size=GetImageSize$original_image );

// Name to save the image as - in this case the same as the original
$new_image $_FILES['filename']['name'];

// Maximum image width
$max_width "200";

// Maximum image height
$max_height "90";

// Resize the image and save

exec("convert $original_image -thumbnail $max_widthx$max_height $new_image");

"File uploaded<br>";

"<img src=\"".$new_image."\">";
else { 
<p>File to upload:</p>
<form method="post" action="<?php echo $PHP_SELF?>" enctype="multipart/form-data"> 
<input type="file" name="filename"  />
<input type="Submit" name="Submit" value="Submit" />
<?php ?>