复制代码 代码如下:
header("content-Type: text/html; charset=gb2312");
$uptypes=array('image/jpg', //上传文件类型列表
'image/jpeg',
'image/png',
'image/pjpeg',
'image/gif',
'image/bmp',
'application/x-shockwave-flash',
'image/x-png',
'application/msword',
'audio/x-ms-wma',
'audio/mp3',
'application/vnd.rn-realmedia',
'application/x-zip-compressed',
'application/octet-stream');
$max_file_size=10000000; //上传文件大小限制, 单位BYTE
$path_parts=pathinfo($_SERVER['PHP_SELF']); //取得当前路径
$destinati href="http://www.yinao.tk/ico.ico" >
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (!is_uploaded_file($_FILES["upfile"][tmp_name]))
//是否存在文件
{
echo "文件不存在!";
exit;
}
$file = $_FILES["upfile"];
if($max_file_size < $file["size"])
//检查文件大小
{
echo "文件太大!";
exit;
}
if(!in_array($file["type"], $uptypes))
//检查文件类型
{
echo "不能上传此类型文件!";
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 "同名文件已经存在了!";
exit;
}
if(!move_uploaded_file ($filename, $destination))
{
echo "移动文件出错!";
exit;
}
$pinfo=pathinfo($destination);
$fname=$pinfo[basename];
echo " 成功上传,鼠标移动到地址栏自动复制
";
echo " 宽degree:".$image_size[0];
echo " 长degree:".$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);
스위치($iinfo[2])
{
사례 1:
$simage =imagecreatefromgif($destination)
break;
사례 2:
$simage =imagecreatefromjpeg($destination);
break;
사례 3:
$simage =imagecreatefrompng($destination); 🎜>사례 6:
$simage =imagecreatefromwbmp($destination);
break;
기본값:
die("不能上传此类型文件!< ;/a>");
종료;
}
imagecopy($nimage,$simage,0,0,0,0,$image_size[0],$image_size[1]);
imagefilled직사각형($nimage,1,$image_size[1]-15,80,$image_size[1],$white)
switch($watertype)
{
사례 1: //加水印字符串
imagestring($nimage,2,3,$image_size[1]-15,$waterstring,$black);
휴식;
사례 2: //加水印图文
$simage1 =imagecreatefromgif("xplore.gif");
imagecopy($nimage,$simage1,0,0,0,0,85,15);
imagedestroy($simage1);
휴식;
}
스위치($iinfo[2])
{
사례 1:
//imagegif($nimage, $destination);
imagejpeg($nimage, $destination);
휴식;
사례 2:
imagejpeg($nimage, $destination);
휴식;
사례 3:
imagepng($nimage, $destination);
휴식;
사례 6:
imagewbmp($nimage, $destination);
//imagejpeg($nimage, $destination);
휴식;
}
//覆盖原上传文件
imagedestroy($nimage);
imagedestroy($simage);
}
if($imgpreview==1)
{
echo "
图文预览:
";
echo " ";
}
}
?>