
<body style="background:blue; font-family:arial;">
<?php
echo "<div style='max-width:600px; padding:9px; background:yellow; font-family:arial; font-size:20px; color:black; margin:1px auto;'>";
echo "File Name: ".$_FILES['userfile']['name']."<br>";
echo "tmp name: ".$_FILES['userfile']['tmp_name']."<br>";
echo "File Type: ".$_FILES['userfile']['type']."<br>";
echo "</div>";
echo "<br>";
$add="extraimages/".$_FILES['userfile']['name']; 
if(move_uploaded_file ($_FILES['userfile']['tmp_name'],$add)){
echo "<center><h2><strong> Successfully uploaded the Image </strong></h2></center>";
header("refresh:3; URL=paper.php");
chmod("$add",0777);

}else
{echo "<center><h2><strong> Failed to upload file Retry</strong></h2></center>";
header("refresh:5; URL=paper.php");
exit;
}

$n_width=150;    // Fix the width of the thumb nail images
$n_height=150;   // Fix the height of the thumb nail imaage

$tsrc="thumbs/".$_FILES['userfile']['name'];   // Path where thumb nail image will be stored
if (!($_FILES['userfile']['type'] =="image/jpeg" OR $_FILES['userfile']['type']=="image/gif")){
echo "Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";
exit;
}


if($_FILES['userfile']['type']=="image/gif")
{
$im=ImageCreateFromGIF($add);
$width=ImageSx($im);          // Original picture width is stored
$height=ImageSy($im);        // Original picture height is stored
$n_height=($n_width/$width) * $height; // Add this line to maintain aspect ratio
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
if (function_exists("imagegif")) {
Header("Content-type: image/gif");
ImageGIF($newimage,$tsrc);
}
elseif (function_exists("imagejpeg")) {
Header("Content-type: image/jpeg");
ImageJPEG($newimage,$tsrc);
}
chmod("$tsrc",0777);
}

if($_FILES['userfile']['type']=="image/jpeg"){
$im=ImageCreateFromJPEG($add); 
$width=ImageSx($im);              // Original picture width is stored
$height=ImageSy($im);             // Original picture height is stored
// Add this line to maintain aspect ratio
$n_height=($n_width/$width) * $height; 
$newimage=imagecreatetruecolor($n_width,$n_height);                 
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$tsrc);
chmod("$tsrc",0777);
}
?>

<!--
<center> reference website:- https://www.plus2net.com/php_tutorial/php_thumbnail.php </center> -->
</body>
