The GD library is a very powerful library for PHP to perform image operations.
Add a line to the php.ini first: Extension=php_gd2.dll
Restart Apache. Make a test page var_dump (Gd_info ()); The output data indicates that the GD library reference was successful.
Image upload Page upload.html
<meta http-equiv= ' content-type ' content= ' text/html; Charset=utf-8 ' >
<title> image Upload </title>
<body>
<form enctype= "Multipart/form-data" action= "upload_img.php" method= "POST" >
<input name= "upfile" type= "file" ><br><br>
<input type= "Submit" value= "Submission" >
</form>
</body>
Handling Page upload_img.php
<?php
Upload Picture Save Address
$uploadfile = "upfiles/". $_files[' upfile ' [' name '];
Thumbnail Save Address
$smallfile = "Upfiles/small_". $_files[' upfile ' [' name '];
if ($_files[' upfile ' [' type ']! = "Image/jpeg")
{
echo ' File type error ';
}
Else
{
Move_uploaded_file ($_files[' upfile ' [' tmp_name '], $uploadfile); Uploading files
$dstW =200;//thumbnail width
$dstH =200;//Thumbnail Height
$SRC _image=imagecreatefromjpeg ($uploadfile);
$srcW =imagesx ($src _image); Get Picture width
$srcH =imagesy ($src _image); Get Picture High
$DST _image=imagecreatetruecolor ($dstW, $dstH);
Imagecopyresized ($dst _image, $src _image,0,0,0,0, $dstW, $dstH, $srcW, $srcH);
Imagejpeg ($dst _image, $smallfile);
echo ' File upload success <br> ';
echo "}
?>
PHP uses the GD library to upload images and create thumbnails