分三个文件啊,
----------------------------------------
第1个文件名:upsave.inc
<%
Dim oUpFileStream
Class UpFile_Class
Dim Form,File,Version,Err
Private Sub Class_Initialize
Version = "无惧上传类 Version V1.0"
Err = -1
End Sub
Private Sub Class_Terminate
'清除变量及对像
If Err <0 Then
Form.RemoveAll
Set Form = Nothing
File.RemoveAll
Set File = Nothing
oUpFileStream.Close
Set oUpFileStream = Nothing
End If
End Sub
Public Sub GetDate (RetSize)
'定义变量
Dim RequestBinDate,sSpace,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
Dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
Dim iFindStart,iFindEnd
Dim iFormStart,iFormEnd,sFormName
'代码开始
If Request.TotalBytes <1 Then
Err = 1
Exit Sub
End If
If RetSize >0 Then
If Request.TotalBytes >RetSize Then
Err = 2
Exit Sub
End If
End If
Set Form = Server.CreateObject ("Scripting.Dictionary")
Form.CompareMode = 1
Set File = Server.CreateObject ("Scripting.Dictionary")
File.CompareMode = 1
s="stream"
Set tStream = Server.CreateObject ("ADODB."&s)
Set oUpFileStream = Server.CreateObject ("ADODB."&s)
oUpFileStream.Type = 1
oUpFileStream.Mode = 3
oUpFileStream.Open
oUpFileStream.Write Request.BinaryRead (Request.TotalBytes)
oUpFileStream.Position = 0
RequestBinDate = oUpFileStream.Read
iFormEnd = oUpFileStream.Size
bCrLf = ChrB (13) &ChrB (10)
'取得每个项目之间的分隔符
sSpace = MidB (RequestBinDate,1, InStrB (1,RequestBinDate,bCrLf)-1)
iStart = LenB (sSpace)
iFormStart = iStart+2
'分解项目
Do
iInfoEnd = InStrB (iFormStart,RequestBinDate,bCrLf &bCrLf)+3
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iFormStart
oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.CharSet = "gb2312"
sInfo = tStream.ReadText
'取得表单项目名称
iFormStart = InStrB (iInfoEnd,RequestBinDate,sSpace)-1
iFindStart = InStr (22,sInfo,"name=""",1)+6
iFindEnd = InStr (iFindStart,sInfo,"""",1)
sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
'如果是文件
If InStr (45,sInfo,"filename=""",1) >0 Then
Set oFileInfo = new FileInfo_Class
'取得文件属性
iFindStart = InStr (iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr (iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileName = Mid (sFileName,InStrRev (sFileName, "\")+1)
oFileInfo.FilePath = Left (sFileName,InStrRev (sFileName, "\")+1)
oFileInfo.FileExt = Mid (sFileName,InStrRev (sFileName, ".")+1)
iFindStart = InStr (iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr (iFindStart,sInfo,vbCr)
oFileInfo.FileType = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileStart = iInfoEnd
oFileInfo.FileSize = iFormStart -iInfoEnd -2
oFileInfo.FormName = sFormName
file.add sFormName,oFileInfo
else
'如果是表单项目
tStream.Close
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iInfoEnd
oUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-2
tStream.Position = 0
tStream.Type = 2
tStream.CharSet = "gb2312"
sFormValue = tStream.ReadText
If Form.Exists (sFormName) Then
Form (sFormName) = Form (sFormName) &", " &sFormValue
else
form.Add sFormName,sFormValue
End If
End If
tStream.Close
iFormStart = iFormStart+iStart+2
'如果到文件尾了就退出
Loop Until (iFormStart+2) = iFormEnd
RequestBinDate = ""
Set tStream = Nothing
End Sub
End Class
'文件属性类
Class FileInfo_Class
Dim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt
'保存文件方法
Public Function SaveToFile (Path)
On Error Resume Next
Dim oFileStream
s="stream"
Set oFileStream = CreateObject ("ADODB."&s)
oFileStream.Type = 1
oFileStream.Mode = 3
oFileStream.Open
oUpFileStream.Position = FileStart
oUpFileStream.CopyTo oFileStream,FileSize
oFileStream.SaveToFile Path,2
oFileStream.Close
Set oFileStream = Nothing
End Function
'取得文件数据
Public Function FileDate
oUpFileStream.Position = FileStart
FileDate = oUpFileStream.Read (FileSize)
End Function
End Class
%>
-------------------------------
第2个文件名:upload.htm
<body bgcolor=#E9F5F5 leftmargin=0 topmargin=0 style="font-size:11px">
<form name="form" enctype="multipart/form-data" action="upload.asp" method=post>
<input type=file name=file1>
<input type=submit name=submit value="上传">
</form>
--------------------------------------
第3个文件名:upload.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../A_Config.asp" -->
<!--#include file="upsave.inc"-->
<body leftmargin="0" topmargin="0" bgcolor=#E9F5F5>
<style type="text/css">*{font-size:12px}</style>
<%
Server.ScriptTimeOut=999999
dim formName,formPath,filename,file_name,fileExt,Filesize,F_Type
call upload()
'===========================无组件上传============================
sub upload()
dim upload,file
set upload=new UpFile_Class ''建立上传对象
upload.GetDate (1000*1024) '取得上传数据,不限大小
if upload.err >0 then
select case upload.err
case 1
Response.Write "<table><tr><td bgcolor=#E9F5F5>请先选择你要上传的文件 [ <a href=# onclick=history.go(-1)>重新上传</a>]</td></tr></table>"
case 2
Response.Write "<table><tr><td bgcolor=#E9F5F5>文件大小超过了限制 [ <a href=# onclick=history.go(-1)>重新上传</a>]</td></tr></table>"
end select
exit sub
else
formPath="../../UpImg/"'upload.form("filepath")
'在目录后加(/)
'if right(formPath,1)<>"/" then formPath=formPath&"/"
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
fileExt=lcase(file.FileExt)
'判断文件类型
if lcase(fileEXT)="asp" and lcase(fileEXT)="asa" and lcase(fileEXT)="aspx" then
CheckFileExt(fileEXT)=false
end if
if CheckFileExt(fileEXT)=false then
response.write "<table><tr><td bgcolor=#E9F5F5>文件格式不正确 [ <a href=# onclick=history.go(-1)>重新上传</a>]</td></tr></table>"
response.end
end if
'付值变量
randomize
ranNum=int(90000*rnd)+10000
file_name=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
filename=file_name&"."&fileExt
rename=filename&"|"
filename1=formPath&filename
Filesize=file.FileSize
'记录文件
if Filesize>0 then '如果 FileSize >0 说明有文件数据
file.SaveToFile Server.mappath(FileName1) ''执行上传文件
'call ImgWriter(FileName1)'添加水印
call checksave() '记录文件
end if
set file=nothing
next
end if
set upload=nothing
response.write "<table><tr><td bgcolor=#E9F5F5>"&FileName&"上传成功![ <a href=# onclick=history.go(-1)>重新上传</a>]</td></tr></table>"
end sub
'判断文件类型是否合格
Private Function CheckFileExt (fileEXT)
dim Forumupload
Forumupload=split("jpg|gif|png","|")
for i=0 to ubound(Forumupload)
if lcase(fileEXT)=lcase(trim(Forumupload(i))) then
CheckFileExt=true
exit Function
else
CheckFileExt=false
end if
next
End Function
Private sub checksave()
'插入上传表并获得ID
response.write "<script>parent.form.txtePath.value='UpImg/"&FileName&"'</script>"
end Sub
Sub ImgWriter(SaveImgPath) '添加水印
dim jpeg
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.Open Server.MapPath(SaveImgPath)
Jpeg.Canvas.Font.Color = &Hffffff
Jpeg.Canvas.Font.Family = "Tahoma"
Jpeg.Canvas.Font.Size = 12
Jpeg.Canvas.Font.ShadowColor = &H000000
Jpeg.Canvas.Font.ShadowXoffset = -1
Jpeg.Canvas.Font.ShadowYoffset = 1
Jpeg.Canvas.Font.Bold = true
Jpeg.Canvas.Print 10, 10, "www.chitw.cn"
Jpeg.Canvas.Pen.Color = &Heeeeee
Jpeg.Canvas.Pen.Width = 1
Jpeg.Canvas.Brush.Solid = False
Jpeg.Canvas.Bar 0, 0, Jpeg.Width, Jpeg.Height
Jpeg.Save Server.MapPath(SaveImgPath)
End Sub
%>
有空到我的学习网上去看看 www.chitw.cn
快速给PDF文件添加水印的方法,支持添加文字或图片水印
步骤1,电脑上下载软件工具后安装打开,点击左边中间的【PDF水印】功能,然后再点击【添加文件】或【添加目录】按钮,将需要加水印的pdf文档导入到软件中,支持批量导入批量添加,节省时间。
步骤2,接下来进行设置,选择一种水印类型(图片水印或文字水印),单个或者多个;然后输入水印文字或上传水印图片;最后设置水印的样式:颜色、大小、缩放比例、透明度、旋转角度、字体、水印密度、位置及边距等。可以一边设置一边在上方预览,方便使用。
步骤3,设置完成后点击【开始转换】按钮,启动软件程序,添加好水印后软件会自动打开一个文件夹,所有添加水印后的pdf文件会全部保存到这里。
步骤4,打开一个pdf可以看到,每个页面都成加上了水印。
//批量处理图片、图片生成缩略图、图片添加水印$dir = opendir (dirname(__FILE__))
while (!!$_file = readdir($dir)){
list($filesname,$kzm)=explode(".",$_file)//获取扩展名
if($kzm=="gif" or $kzm=="jpg" or $kzm=="JPG" or $kzm=="png") {
if(!makethumb("$_file","120","120","100")){
echo '执行成功!'
}else{
echo '执行失败!'
}
}
}
closedir($dir)
/**
* 处理缩略图并添加水印函数
* @access publiuc
* @param $srcFile-----------图片文件名
* @param $dstFile-----------另存的文件名
* @param $dstW-------------图片保存的宽度
* @param $dstH--------------图片保存的高度
* @param $rate---------------图片保存的品质
* @param $markwords-----水印文字
* @param $markimage-----水印图片
* @param 使用方法 makethumb("a.jpg","b.jpg","120","120","100")
*/
function makethumb($srcFile/*,$dstFile*/,$dstW,$dstH,$rate=100/*,$markwords=null,$markimage=null*/) {
$data = GetImageSize($srcFile)
switch($data[2]) {
case 1:
$im=@ImageCreateFromGIF($srcFile)
break
case 2:
$im=@ImageCreateFromJPEG($srcFile)
break
case 3:
$im=@ImageCreateFromPNG($srcFile)
break
}
if(!$im) return False
$srcW=ImageSX($im)
$srcH=ImageSY($im)
$dstX=0
$dstY=0
if ($srcW*$dstH>$srcH*$dstW) {
$fdstH = round($srcH*$dstW/$srcW)
$dstY = floor(($dstH-$fdstH)/2)
$fdstW = $dstW
}
else
{
$fdstW = round($srcW*$dstH/$srcH)
$dstX = floor(($dstW-$fdstW)/2)
$fdstH = $dstH
}
$ni=ImageCreateTrueColor($dstW,$dstH)
$dstX=($dstX<0)?0:$dstX
$dstY=($dstX<0)?0:$dstY
$dstX=($dstX>($dstW/2))?floor($dstW/2):$dstX
$dstY=($dstY>($dstH/2))?floor($dstH/s):$dstY
$white = ImageColorAllocate($ni,255,255,255)
$black = ImageColorAllocate($ni,0,0,0)
imagefilledrectangle($ni,0,0,$dstW,$dstH,$white)// 填充背景色
ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fdstW,$fdstH,$srcW,$srcH)
//if($markwords!=null){
// $markwords=iconv("gb2312","UTF-8",$markwords)
// //转换文字编码
// ImageTTFText($ni,20,30,450,560,$black,"simhei.ttf",$markwords) //写入文字水印,参数依次为,文字大小|偏转度|横坐标|纵坐标|文字颜色|文字类型|文字内容
//}elseif($markimage!=null) {
// $wimage_data = GetImageSize($markimage)
// switch($wimage_data[2]) {
// case 1:
// $wimage=@ImageCreateFromGIF($markimage)
// break
// case 2:
// $wimage=@ImageCreateFromJPEG($markimage)
// break
// case 3:
// $wimage=@ImageCreateFromPNG($markimage)
// break
// }
// imagecopy($ni,$wimage,500,560,0,0,88,31) //写入图片水印,水印图片大小默认为88*31
// imagedestroy($wimage)
//}
$dstFile = $srcFile.'.gif'
ImageJpeg($ni,$dstFile,$rate)
//ImageJpeg($ni,$srcFile,$rate)
imagedestroy($im)
imagedestroy($ni)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)