<! DOCTYPE html>
<!--HTML5 Forms--
<form method= "POST" action= "enctype=" Multipart/form-data ">
<input type= "file" name= "Picture" ><br/>
<input type= "submitted" name= "submit" value= "Submission" >
</form>
<!--PHP code section--
<?php
if (Isset ($_post[' submit '))
{
$filename =$_files[' picture ' [' Name '];//get the name of the uploaded file
$type =$_files[' picture ' [' type '];//get the type of upload file
$upfile = ". /good/image/ex5_9.jpg ";//the path and filename of the file after uploading
$small _upfile= ". /good/image/ex5_9_small.jpg ";//the path and file name of the thumbnail image after uploading
if (! $filename)//Determine if the file exists
{
echo "<script>alert (' file does not exist!) ') </script> ";
}
else if ($type! = ' image/pjpeg ')//Determine if the file is in JPEG format
//{
echo "<script>alert (' file format is incorrect!) ') </script> ";
//}
Else
{
Copy the upload file and save the file as $upfile
Move_uploaded_file ($_files[' picture '] [' tmp_name '], $upfile);
$DST _w=150;//Set the width of the thumbnail image
$DST _h=150;//Set the height of the thumbnail image
$SRC _image=imagecreatefromjpeg ($upfile);//Read the uploaded file and create an image
$src _w=imagesx ($src _image);//Get the width of the image
$src _h=imagesy ($src _image);//Get the image high
$DST _image=imagecreatetruecolor ($dst _w, $dst _h);//Create a new image
Redefine the image $src_image size and write to the new image $dst_image
Imagecopyresized ($dst _image, $src _image,0,0,0,0, $dst _w, $dst _h, $src _w, $src _h);
Imagejpeg ($dst _image, $small _upfile);//Save new image as $small_upfile
echo "file uploaded successfully, thumbnail image as follows:<br/>";
echo "Imagedestroy ($src _image);
Imagedestroy ($dst _image);
}
}
?>
PHP thumbnail image