<?php
$uptypes=array('image/jpg', //Upload file type list
'image/jpeg',
'image/png',
'image/pjpeg',
'image/gif',
'image/bmp',
'image/x-png');
$max_file_size=5000000; //Upload file size limit, unit BYTE
$destination_folder="upload/"; //Upload file path
$watermark=1; //Whether to attach a watermark (1 is a watermark, others are not a watermark);
$watertype=1; //Watermark type (1 is text, 2 is picture)
$waterposition=1; //Watermark position (1 is the lower left corner, 2 is the lower right corner, 3 is the upper left corner, 4 is the upper right corner, and 5 is the center);
$waterstring=""; //Watermark string
$waterimg=""; //Watermark picture
$imgpreview=1; //Whether to generate a preview image (1 is generated, others are not generated);
$imgpreviewsize=1/2; //Thumbnail scale
?>
<html>
<head>
<title>M4U BLOG - </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">body,td{font-family:tahoma,verdana,arial;font-size:11px;line-height:15px;background-color:white;color:#666666;margin-left:20px;}
strong{font-size:12px;}
aink{color:#0066CC;}
a:hover{color:#FF6600;}
aisited{color:#003366;}
a:active{color:#9DCC00;}
{}
{height:20px;background:url("?i=dots" repeat-x bottom}</style>
</head>
<body>
<center><form enctype="multipart/form-data" method="post" name="upform">
Upload file: <br><br><br>
<input name="upfile" type="file" style="width:200;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" size="17">
<input type="submit" value="upload" style="width:30;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" size="17"><br><br><br>
The file types allowed to be uploaded are: jpg|jpeg|png|pjpeg|gif|bmp|x-png|swf <br><br>
<a href="">Return</a>
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (!is_uploaded_file($_FILES["upfile"][tmp_name]))
//Is there a file
{
echo "<font color='red'>file does not exist!</font>";
exit;
}
$file = $_FILES["upfile"];
if($max_file_size < $file["size"])
//Check file size
{
echo "<font color='red'>file is too big!</font>";
exit;
}
if(!in_array($file["type"], $uptypes))
//Check file type
{
echo "<font color='red'> can only upload image files or Flash!</font>";
exit;
}
if(!file_exists($destination_folder))
mkdir($destination_folder);
$filename=$file["tmp_name"];
$image_size = getimagesize($filename);
$pinfo=pathinfo($file["name"]);
$ftype=$pinfo[extension];
$destination = $destination_folder.time().".".$ftype;
if (file_exists($destination) && $overwrite != true)
{
echo "<font color='red'>file with the same name already exists!</a>";
exit;
}
if(!move_uploaded_file ($filename, $destination))
{
echo "<font color='red'>Error moving the file!</a>";
exit;
}
$pinfo=pathinfo($destination);
$fname=$pinfo[basename];
echo " <font color=red> has been uploaded successfully</font><br>File name: <font color=blue>".$destination_folder.$fname."</font><br>";
echo " Width:".$image_size[0];
echo " Length:".$image_size[1];
if($watermark==1)
{
$iinfo=getimagesize($destination,$iinfo);
$nimage=imagecreatetruecolor($image_size[0],$image_size[1]);
$white=imagecolorallocate($nimage,255,255,255);
$black=imagecolorallocate($nimage,0,0,0);
$red=imagecolorallocate($nimage,255,0,0);
imagefill($nimage,0,0,$white);
switch ($iinfo[2])
{
case 1:
$simage =imagecreatefromgif($destination);
break;
case 2:
$simage =imagecreatefromjpeg($destination);
break;
case 3:
$simage =imagecreatefrompng($destination);
break;
case 6:
$simage =imagecreatefromwbmp($destination);
break;
default:
die("<font color='red'> cannot upload this type of file!</a>");
exit;
}
imagecopy($nimage,$simage,0,0,0,0,$image_size[0],$image_size[1]);
imagefilledrectangle($nimage,1,$image_size[1]-15,80,$image_size[1],$white);
switch($watertype)
{
case 1: //Add a watermark string
imagestring($nimage,2,3,$image_size[1]-15,$waterstring,$black);
break;
case 2: // Add watermark picture
$simage1 =imagecreatefromgif("");
imagecopy($nimage,$simage1,0,0,0,0,85,15);
imagedestroy($simage1);
break;
}
switch ($iinfo[2])
{
case 1:
//imagegif($nimage, $destination);
imagejpeg($nimage, $destination);
break;
case 2:
imagejpeg($nimage, $destination);
break;
case 3:
imagepng($nimage, $destination);
break;
case 6:
imagewbmp($nimage, $destination);
//imagejpeg($nimage, $destination);
break;
}
//Overwrite original uploaded file
imagedestroy($nimage);
imagedestroy($simage);
}
if($imgpreview==1)
{
echo "<br>Picture preview:<br>";
echo "<a href=\"".$destination."\" target='_blank'><img src=\"".$destination."\" width=".($image_size[0]*$imgpreviewsize)." height=".($image_size[1]*$imgpreviewsize);
echo " alt=\"Image preview:\rFile name:".$destination."\rUpload time:\" border='0'></a>";
}
}
?>
</center>
</body>
</html>