上传问题函数 拜托了
[code=PHP][/code]
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=20000000; //上传文件大小限制, 单位BYTE
$path_parts=pathinfo($_SERVER['PHP_SELF']); //取得当前路径
$destination_folder="up/"; //上传文件路径
$imgpreview=1; //是否生成预览图(1为生成,其他为不生成);
$imgpreviewsize=1/2; //缩略图比例
$file=&$HTTP_POST_FILES['userfile'];
// var_dump ($file);
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;
$fname = time().".".$ftype;
if (file_exists($destination) && $overwrite != true)
{
echo "
同名文件已经存在了!";
exit;
}
if(!move_uploaded_file ($filename, $destination))
{
echo "移动文件出错!";
exit;
}else{
//添加写入数据库的部分
// 创建数据库连接
$con = mysql_connect('localhost', 'root', '111') or die('Could not connect: ' . mysql_error());
//echo 'Connected successfully';
$db=mysql_select_db('download',$con);
mysql_query("set names gb2312");
if (!$db){
die ("Can\'t use download : " . mysql_error());
}else{
// 将用户信息插入数据库的user表
$sql = "INSERT INTO `register`.`scb` (`id`,`fl` ,`zuoz` ,`filename` ,`des` ,`fsize` ,`ftype` ,`utime` )VALUES (NULL ,'".$fl."' ,'".$zuo."' ,".$fname."' , '', '".$file["size"]."', '".$file["type"]."',NOW());";
$result =mysql_query($sql);
if (!$result) {
// 释放结果集
mysql_free_result($result);
// 关闭连接
mysql_close($db);
echo '数据记录插入失败!';
exit;
}
}
}
$pinfo=pathinfo($destination);
$fname=$pinfo[basename];
echo "上传文件地址:http://".$_SERVER['SERVER_NAME'].$path_parts["dirname"]."/".$destination_folder.$fname." |
";
echo " 宽度:".$image_size[0];
echo " 长度:".$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: