PHP thumbnail image

Source: Internet
Author: User

<! 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.