upfile.htm<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<head>
</head>
<body bgcolor="#FFFFFF" text="#333333">
<form name="form1" method="post" action="upfile.asp" enctype="multipart/form-data" >
<input type="hidden" name="act" value="upload">
<input type="hidden" name="filepath" class="tx" style="width:400" value="图片保存路径">
<table width="450" height="12" border="0" align="left" cellpadding="0" cellspacing="0" bordercolor="#EFEFEF" >
<tr align="center" valign="middle" id="newspic">
<td align="left" id="upid" height="31">
选择上传图片:<input type="file" name="file1" style="width:300" class="tx1"><br>
上传图片说明:<input type="text" name="tail" style="width:300" class="tx1">
<input type="submit" name="Submit" value="上 传" class="tx1">
</td>
</tr>
</table>
</form>
</body>
</html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<head>
</head>
<body bgcolor="#FFFFFF" text="#333333">
<form name="form1" method="post" action="upfile.asp" enctype="multipart/form-data" >
<input type="hidden" name="act" value="upload">
<input type="hidden" name="filepath" class="tx" style="width:400" value="图片保存路径">
<table width="450" height="12" border="0" align="left" cellpadding="0" cellspacing="0" bordercolor="#EFEFEF" >
<tr align="center" valign="middle" id="newspic">
<td align="left" id="upid" height="31">
选择上传图片:<input type="file" name="file1" style="width:300" class="tx1"><br>
上传图片说明:<input type="text" name="tail" style="width:300" class="tx1">
<input type="submit" name="Submit" value="上 传" class="tx1">
</td>
</tr>
</table>
</form>
</body>
</html>
<!--#include FILE="upload_5xsoft.inc"-->
<html>
<head>
<title>Upfile</title>
</head>
<body>
<form name="upfilecode" action="" method="post"><%
dim upload,file,formName,formPath,iCount,filename,fileExt,pictail
set upload=new upload_5xSoft ''建立上传对象
pictail =upload.form("tail") ''收集图片信息
if upload.form("filepath")="" then ''得到上传目录
response.write "请输入要上传至的目录!"
set upload=nothing
response.end
else
formPath=upload.form("filepath")
if right(formPath,1)<>"/" then formPath=formPath&"/" '在目录后加(/)
end ifiCount=0
for each formName in upload.file '列出所有上传了的文件
set file=upload.file(formName) '生成一个文件对象
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&file.FileName
session("filename") = filename if file.filesize<10 then
response.write "<font style='font-size:12px'>请先选择你要上传的图片 [ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
response.end
end if
if file.filesize>150000 then
response.write "<font style='font-size:12px'>图片大小超过了限制 [ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
response.end
end if fileExt=lcase(right(file.filename,4)) if fileExt<>".gif" and fileExt<>".jpg" then
response.write "<font style='font-size:12px;'>文件格式不对,本系统只接受GIF和JPG图形文件。 [ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
response.end
end if dim upfilepath,uped
upfilepath = ""
session("uped") = session("uped") & "aa"
if file.FileSize>0 then '如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath(formPath&filename) '保存文件
upfilepath=formPath&filename
if session("uped") = "aa" then
session("upfiled") = "<IMG SRC="&upfilepath&" BORDER='0' align=center><br><br>"
else
session("upfiled") = session("upfiled") & "<IMG SRC="&upfilepath&" BORDER='0' align=center><br><br>"
end if
session("upfilenow") = upfilepathresponse.write "<font style={font-size:12px;}>"&upfilepath & "图片上传成功"&" <a href=upfile.htm>[继续上传]</a></font>"
end if
set file=nothing
next
set upload=nothing '删除此对象%>
也许有用
/////////////////////////////////////////////////////////////////////
欢迎大家使用编程文档手册V3.2,编程辅助类软件 集编程文档的收集、查询、浏览、编辑等功能于一体的辅助编程类软件。通过日积月累,相信本软件将给广大程序开发人员以及编程爱好者们带来很大的帮助。下载地址:http://www.yueya.com/Promanual.exe
详细说明与注册地址:http://www.sharebank.com.cn/soft/soft_view.php?id=10648
官方网站:http://promanual.jijun.org
工作室站点:http://www.jijun.org欢迎大家使用,欢迎大家多多指教。
/////////////////////////////////////////////////////////////////////
/*
* A class used to upload mulitpicture
* $picname ,array, the name of the uploaded picture
* $picsize, array, the size of the uploaded picture
* $error; the Error information
* $hasuploadnum , int ,the number of the uploaded picture
*/class Upload
{
var $picname;
var $picsize;
var $error;
var $hasuploadnum;
function Upload()
{
$this->error = "";
$this->picname = array();
$this->picsize = array();
}
/*
*function used to upload one picture
*/
function upload_pic($tmpname, $name, $type, $size, $maxsize=5000, $file_path="")
{
if (($tmpname=="")||($name=="")||($type=="")||($size==""))
{
$this->error .= "Has a wrong parameter!<br>";
return false;
}
$name_array = explode(".",$name);
$suffix = $name_array[1];
$pic_name=time().rand(1,100).".".$suffix;
$type_array = explode("/",$type);
$file_type = $type_array[0];
if ($file_type!="image")
{
$this->error .= "Wrong type of the uploadfile<br>";
return false;
}
//判断图片大小
if ($size>$maxsize)
{
$this->error.="The size of the picture has get ahead of maxsize!<br>";
return false;
}
//拷贝临时文件到指定目录
if (move_uploaded_file($tmpname,$file_path.$name))
{
if (rename($file_path.$name,$file_path.$pic_name)) //将图片改成指定的名称
{
return $pic_name;
}
else
{
$this->error .= "Connot rename picture!<br>";
unlink($file_path.$name);
}
} //end if
return false;
} //end function
/*
* function used to delete uploaded picture
*/
function err_del($n,$thefile,$file_path="")
{
for($i=0; $i<$n; $i++)
{
unlink($file_path.$thefile[$i]);
}
}
/*
* A function used to upload mulitpicture
* $file : the post filename
* $n : the number of post items
* $maxsize : the max size of the permissive upload picture
* $file_path : the dir of the picture
*/
function Mulitpic_upload($file,$n,$maxsize,$file_path)
{
$num = 0;
$hasuploadname[] = array();
if ($file=="")
{
$this->error .= "No file upload!<br>";
return false;
}
if ($maxsize<0)
{
$this->error .= "Error maxsize!<br>";
return false;
}
if (is_dir($file_path)!=1)
{
if(!mkdir(mkdir($file_path)))
{
$this->error .= "Create dir error!<br>";
return false;
}
}
for($i=0; $i<$n; $i++)
{
if ($_FILES[$file]['size'][$i]>0)
{
$tmpname = $_FILES[$file]['tmp_name'][$i];
$name = $_FILES[$file]['name'][$i];
$type = $_FILES[$file]['type'][$i];
$size = round($_FILES[$file]['size'][$i]/1024,2);
if (in_array($name,$hasuploadname))
{
$this->err_del($num,$this->picname,$file_path);
$this->error .= "Picture ".$name." has exists!<br>";
return false;
}
$hasuploadname[$num] = $name;
$pic_name = $this->upload_pic($tmpname,$name,$type,$size,$maxsize,$file_path);
$this->picname[$num] = $pic_name;
$this->picsize[$num] = $size;
if(!$pic_name)
{
$this->err_del($num,$this->picname,$file_path);
$this->error .= "Upload picture error!<br>";
return false;
}
$num++;
} //end if
}//end for
$this->hasuploadnum = $num;
}// end function
function Getname()
{
return $this->picname;
}
function Getsize()
{
return $this->picsize;
}
function Getnum()
{
return $this->hasuploadnum;
}
function Geterror()
{
return $this->error;
}
function showpic()
{
for($i=0; $i<$this->Getnum(); $i++)
{
echo $this->picname[$i]." ".$this->picsize[$i]."<br>";
}
}
}
?>
$imgfile_name = $_FILES["bimgs"]["name"];
$imgfile_type = $_FILES["bimgs"]["type"];
$imgfile_size = $_FILES["bimgs"]["size"];
if (! empty($imgfile))
{
//上传错误
if ($_FILES["bimgs"]["error"]<>0)
{echo "图片上传错误!";
exit(0);}
//0字节文件
if ($imgfile_size==0)
{echo "上传文件零字节!请检查!";
exit(0);}
//是否为图片文件
if(! @preg_match ("/image/i",$imgfile_type))
{echo "上传文件不是图片,请检查!";
exit(0);}
//上传文件
//处理文件名
$tmptime=gettimeofday();
$tmpsec=$tmptime["sec"]+1;
$tmparray=explode(".",$imgfile_name);
$tmphz=$tmparray[count($tmparray)-1];
$dest1=$tmpsec.".".$tmphz;
//echo $dest1;
if(@copy($imgfile,$conf_uploadpath.$_SESSION[s_id]."/".$dest1))
{$_SESSION[sbimg]=$imgfile;
@unlink($imgfile);
}
else
{echo "文件无法保存,请重试!";
exit(0);}
}/* sql 语句*/
int imagesy ( resource image)--取得图像高度
asp的麻烦继续发完吧
windows下需要加载php_gd.dll
参数一般要用其他image函数来创建
var $the_temp_file;
var $upload_dir;
var $extensions;
var $http_error;
var $message;
function file_upload() {
$this->upload();
}
function upload() {
$source_file = trim($this->the_temp_file);
$dest_file = trim($this->the_file);
if ($source_file != "") {
$ext = $this->validateExtension();
if ($ext) {
if (is_uploaded_file($source_file)) {
if ($this->move_upload($source_file, $dest_file)) {
$this->message = "File: <b>".$dest_file."</b> successfully uploaded!";
return true;
}
} else {
$this->report_error();
return false;
}
} else {
$poss_ext = implode(" ", $this->extensions);
$this->message = "Only files with the following extensions are allowed: <b>".$poss_ext."</b>";
return false;
}
} else {
$this->message = "Please select a file for upload.";
}
}
function validateExtension() {
$file_name = trim($this->the_file);
$extension = strtolower(strrchr($file_name,"."));
$ext_array = $this->extensions;
if (in_array($extension, $ext_array)) {
return true;
} else {
return false;
}
}
function check_dir() {
if (!is_dir($this->upload_dir)) {
return false;
} else {
return true;
}
}
function move_upload() {
umask(0);
if ($this->check_dir()) {
$newfile = $this->upload_dir.trim($this->the_file);
$tmp_file = trim($this->the_temp_file);
if (move_uploaded_file($tmp_file, $newfile)) {
system("chmod 0755 $newfile");
return true;
} else {
return false;
}
} else {
$this->message = "Sorry the upload directory doesn't exist!";
}
}
// some error (HTTP)reporting, change the messages or remove options if you like.
function report_error() {
switch($this->http_error) {
case 1:
$this->message = "The uploaded file exceeds the max. upload filesize directive in the server configuration";
break;
case 2:
$this->message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form";
break;
case 3:
$this->message = "The uploaded file was only partially uploaded";
break;
case 4:
$this->message = "No file was uploaded";
break;
default:
$this->message = "There was a problem with your upload.";
}
}
}
————————————————————————————————<form name="uppic" method="post" action="uppic.php" enctype="multipart/form-data" >
<font size="2" color="#333300">
选择上传图片:
<input type="file" name="pic_file" style="width:300" title="请注意上传的文件大小不要超过200K,尺寸不要大于240*320,文件名中不要带有空格" ><br>
<br>
上传图片说明:
<input type="text" name="pic_text" style="width:300" size="20" maxlength="50" title="请输入图片的说明文字,长度不得超过25个字">
<br>
<br>
<input type="submit" name="Submit" value="上 传" style="font-size: 10pt; font-family: 宋体; color: #333300"><br>
</form>uppic.php
————————————————————————————————<?
$pic_text = $_POST['pic_text'];
if ( $pic_text == "" )
{
$pic_text = "无";
}
$con_type = 0;
$con_size = 0;
$con_pix = 0;
//判断是否是图片类型的文件
if ( ( $_FILES['pic_file']['type']=="image/gif" )
|| ( $_FILES['pic_file']['type']=="image/pjpeg" )
|| ( $_FILES['pic_file']['type']=="image/jpeg" )
|| ( $_FILES['pic_file']['type']=="image/bmp" )
|| ( $_FILES['pic_file']['type']=="image/tiff" )
|| ( $_FILES['pic_file']['type']=="image/jp2" )
|| ( $_FILES['pic_file']['type']=="image/png" )
|| ( $_FILES['pic_file']['type']=="image/iff" ) )
{
$con_type = 1;//控制上传文件的类型
$image_size = getimagesize($_FILES['pic_file']['tmp_name']); if ( ( $image_size[0] <= 240 ) && ( $image_size[1] <= 320 ) )
{
$con_pix = 1;//控制上传图片的尺寸
}
}
if ( $_FILES['pic_file']['size']<=204800 )
{
$con_size = 1;//控制上传图片的大小
}
if ( ( $con_type == 1 ) && ( $con_size == 1 ) && ( $con_pix == 1 ) )
{
//通过函数getdate提取出系统的年、天、时、分、秒作为上传图片的文件名
$today = getdate(); $name_main = ""; $string_year = (string) $today[year]; $string_yday = (string) $today[yday];
if ( $today[yday] < 10 )
{
$string_yday = "0".$string_yday;
}
if ( $today[yday] < 100 )
{
$string_yday = "0".$string_yday;
}
$string_hours = (string) $today[hours];
if ( $today[hours] < 10 )
{
$string_hours = "0".$string_hours;
} $string_minutes = (string) $today[minutes];
if ( $today[minutes] < 10 )
{
$string_minutes = "0".$string_minutes;
}
$string_seconds = (string) $today[seconds];
if ( $today[seconds] < 10 )
{
$string_seconds = "0".$string_seconds;
} $name_main = $string_year.$string_yday.$string_hours.$string_minutes.$string_seconds;
//定义上传图片的扩展名
switch ( $_FILES['pic_file']['type'] )
{
case "image/gif":
$name_ext = ".gif";
break; case "image/pjpeg":
$name_ext = ".jpg";
break; case "image/jpeg":
$name_ext = ".jpg";
break; case "image/bmp":
$name_ext = ".bmp";
break; case "image/tiff":
$name_ext = ".tif";
break; case "image/jp2":
$name_ext = ".jp2";
break; case "image/png":
$name_ext = ".png";
break; case "image/iff":
$name_ext = ".iff";
break;
} $filename = 'upload_tmp/'.$name_main.$name_ext;
$copymes = copy( $_FILES['pic_file']['tmp_name'] , $filename );
//如果是图形文件格式且大小和尺寸合适则显示
echo "<p><img src='";
echo $filename;
echo "'align=center border=0><br>";
}
else
{
echo '<font face="黑体" color="#ff0000" style="font-size: 28"> 上传错误!</font> ';
}
?>
<?
if ( ( $con_type == 1 ) && ( $con_size == 1 ) && ( $con_pix == 1 ) )
{
echo '<b>说明文字:</b>'.$pic_text;
}
else
{
echo '<b>错误提示:</b>';
if ( $con_type == 0 )
{
echo '上传的文件不是本系统能识别的图片格式 ';
}
if ( ( $con_type == 1 ) && ( $con_pix == 0 ) )
{
echo '上传的图片文件尺寸('.$image_size[0].'*'.$image_size[1].')不在规格(240*320)之内 ';
}
if ( $con_size == 0 )
{
echo '上传的文件大小('.(int) ( ($_FILES['pic_file']['size']) / 1000 ).'K)超过了200K';
}
}
?>