<html>
<head>
<title>ZwelL图片上传程序</title>
<style type=text/css>
<!
body
{
fontsize: pt;
}
input
{
backgroundcolor: #CCFF;
border: px inset #CCCCCC;
}
>
</style>
</head>
<body>
<form enctype=multipart/formdata method=post name=upform>
上传文件:
<input name=upfile type=file>
<input type=submit value=上传><br>
允许上传的文件类型为:<?=implode( $uptypes)?>
</form>
<?php
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 文件类型不符!$file[type];
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_foldertime()$ftype;
if (file_exists($destination) && $overwrite != true)
{
echo 同名文件已经存在了;
exit;
}
if(!move_uploaded_file ($filename $destination))
{
echo 移动文件出错;
exit;
}
$pinfo=pathinfo($destination);
$fname=$pinfo[basename];
echo <font color=red>已经成功上传</font><br>文件名:
<font color=blue>$destination_folder$fname</font><br>;
echo 宽度:$image_size[];
echo 长度:$image_size[];
echo <br> 大小:$file[size] bytes;
if($watermark==)
{
$iinfo=getimagesize($destination$iinfo);
$nimage=imagecreatetruecolor($image_size[]$image_size[]);
$white=imagecolorallocate($nimage);
$black=imagecolorallocate($nimage);
$red=imagecolorallocate($nimage);
imagefill($nimage$white);
switch ($iinfo[])
{
case :
$simage =imagecreatefromgif($destination);
break;
case :
$simage =imagecreatefromjpeg($destination);
break;
case :
$simage =imagecreatefrompng($destination);
break;
case :
$simage =imagecreatefromwbmp($destination);
break;
default:
die(不支持的文件类型);
exit;
}
imagecopy($nimage$simage$image_size[]$image_size[]);
imagefilledrectangle($nimage$image_size[]$image_size[]$white);
switch($watertype)
{
case : //加水印字符串
imagestring($nimage$image_size[]$waterstring$black);
break;
case : //加水印图片
$simage =imagecreatefromgif(xploregif);
imagecopy($nimage$simage);
imagedestroy($simage);
break;
}
switch ($iinfo[])
{
case :
//imagegif($nimage $destination);
imagejpeg($nimage $destination);
break;
case :
imagejpeg($nimage $destination);
break;
case :
imagepng($nimage $destination);
break;
case :
imagewbmp($nimage $destination);
//imagejpeg($nimage $destination);
break;
}
//覆盖原上传文件
imagedestroy($nimage);
imagedestroy($simage);
}
if($imgpreview==)
{
echo <br>图片预览:<br>;
echo <ccid_file values=\ width=($image_size[]*$imgpreviewsize)
height=($image_size[]*$imgpreviewsize);
echo alt=\图片预览:\r文件名:$destination\r上传时间:\ />;
}
}
?>
</body>
</html>
[] []