1. 程式人生 > >ASP批量上傳和編輯圖片

ASP批量上傳和編輯圖片

關於這個問題也算是老生常談,但是我相信還是有不會的朋友。寫這篇文章主要是對那些需要的朋友,對於大牛,就可以不看了。大笑,寫的不好,還請大牛指點一二啊。

本人QQ:1127173874.

第一,相關的JS檔案和上傳類,主要是jquery-1.4.2.js和jquery.livequery.js,UpLoadClass.asp這三塊我會打包給大家的。

第二,JS程式碼

<script type="text/javascript">
var bOnLoad = true;
function setFileFileds(num){
num = parseInt(num);
for(var i=0,str="";i<num;i++){

str+="<input name=\"strFile"+i+"\" type=\"file\" id=\"strFile"+i+"\"><br />";
document.getElementById("objFiles").innerHTML=str;
bOnLoad = false;
}
}


function DownImage(ImgD,MaxWidth,MaxHeight){  
    var image=new Image();  
    image.src=ImgD.src;  
    if(image.width>0 && image.height>0){  
        var rate = (MaxWidth/image.width < MaxHeight/image.height)?MaxWidth/image.width:MaxHeight/image.height; 
        if(rate <= 1){           
            ImgD.width = image.width*rate; 
            ImgD.height =image.height*rate; 
        } 
    }  

$(function(){
$("#csp img").livequery("click",function(){
var da=confirm('確認要刪除該圖片?');
if(da==true)
{
var a=$(this).attr("src");
var B=a+",";
var A=$("#pic1").val();
//var C="http://"+document.domain;
var C="../UploadFiles/";
B=B.replace(C,"");
a=a.replace(C,"");
A=A.replace(B,"");


$.post("deltp.asp",{cname:a});


$(this).parent().hide();


$("#pic1").val(A);
}


})
})
</script>

效果圖


第三 儲存程式碼

'======================================儲存圖片
dim request2,formPath,formName,intCount,intTemp
set request2=new UpLoadClass
'設定檔案允許的附件型別為gif/jpg/rar/zip
request2.FileType="gif/jpg/bmp/jpeg"
'設定伺服器檔案儲存路徑
request2.SavePath="../UploadFiles/"
'設定字符集
request2.Charset="gb2312"
'開啟物件
request2.Open() 
temp_str=""
intCount=0
for intTemp=1 to Ubound(request2.FileItem)
formName=request2.FileItem(intTemp)
temp_str=temp_str&formPath&request2.form(formName)&","
if request2.form(formName&"_Err")=0 then intCount=intCount+1
next
temp_str2=temp_str
'===========================================

str="insert into sys_gdimg(img)values('"&temp_str2&"')"

conn.execute(str)

以上就是ASP的批量儲存圖片的內容,希望對大家有用。