2009-11-02 25 views
1

嘿我需要以下方面的幫助。 我有一個網站, 雖然我不是一個100%的程序員,但我試圖在網站的編程中進行導航。它在asp.net 2.0中工作。複製上傳

我有一個圖片庫,但唯一的問題是,我一次只能上傳1張圖片。我需要一些幫助,我可以如何在網站上集成多個圖像。

下面爲album.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> 
<!-- #INCLUDE file="inc/settings.asp" --> 
<!-- #INCLUDE file="inc/functions.asp" --> 
<!-- #INCLUDE file="inc/db_connect.asp" --> 
<!-- #INCLUDE file="inc/check_login.asp" --> 
<!--#INCLUDE file="fckeditor/fckeditor.asp" --> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<script type="text/javascript" src="js/script.js"></script> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Xaghra Scouts</title> 
<link href="styles.css" rel="stylesheet" type="text/css" /> 
<% 
cat = decrypt(request("cat") & "") 
set fs=Server.CreateObject("Scripting.FileSystemObject") 
isSub = true 
%> 
</head> 
<body> 
<!-- #INCLUDE file="layout_top.asp" --> 
<%if loggedin then%> 
<table align="center" border="0" cellspacing="0" cellpadding="5" class="main"> 
    <tr > 
    <td align="center" style="padding:15px;" colspan="2"> 
     <form action="album.asp" method="post" id="selectCategory"> 
     <b>SELECT CATEGORY:&nbsp;</b> 
     <select name="cat" style="font-size:12px; width:160px; height:19px;" onChange="javascript: document.getElementById('selectCategory').submit();"> 
     <option selected>Uncategorized</option> 
     <% 
        set fo=fs.GetFolder(Server.MapPath("images/gallery")) 
        for each x in fo.SubFolders 
         Response.write("<option value='" & encrypt(x.Name) & "'") 
         if cat = x.Name then 
          response.write("selected") 
         end if 
         Response.write(">" & x.Name & "</option>") 
        next 
       %> 
     </select> 
     </form> 
    </td> 
    </tr> 
    <tr style="color:#666666; font-size:12px;"> 
    <td colspan="2" align="left"> 
     <br> 
      <% 
      if cat <> "" and fs.FolderExists(Server.MapPath("images/gallery/" & cat)) then 
       set fo=fs.GetFolder(Server.MapPath("images/gallery/" & cat)) 
       path = "gallery/" & cat 
      else 
       set fo=fs.GetFolder(Server.MapPath("images/gallery")) 
       path = "gallery" 
      end if 

      for each file in fo.files 
       if right(lcase(file.Name),3) = "jpg" then%> 
        <div style="height:120px; width:160px; text-align:center; float:left;"><img src="thumbnail.aspx?picture=<%=server.URLEncode("images/" & path & "/" & file.Name)%>&maxWidth=160&maxHeight=100" style="border:1px solid #ffffff;"><br> 
      <a onClick="javascript:ConfirmChoice('Are you sure you wish to delete this picture?','delete_image.asp?cat=<%=encrypt(cat)%>&file=<%=Server.URLEncode("images/" & path & "/" & file.Name)%>');"href="#" style="font-size:10px">DELETE</a></div> 
       <%end if 
      next 
      %> 
    </tr> 
    <tr style="color:#666666; font-size:12px;"> 
    <td colspan="2" align="left"> 
    <div style="text-align:center;"> 
    <form action="file_upload.asp?FileName=<%=Server.URLEncode(uniqueName())%>&FilePath=<%=Server.URLEncode("images/" & path)%>&AcceptedFiles=<%=Server.URLEncode("JPG")%>&Redirect=<%=Server.URLEncode("album.asp")%>&MaxHeight=480&MaxWidth=640" enctype="multipart/form-data" method="post"> 
    <table align="center" border="0" cellspacing="0" cellpadding="20" class="main"> 
     <tr> 
     <td align="center" class="details"> 
        <div style="color:#FF0000; font-size:10px;"><%if (request.QueryString("formatError") & "") <> "" then%>INVALID FILE FORMAT (.JPG ONLY)<%end if%>&nbsp;</div><br> 
      <input name="file" type="file" accept="jpg/jpeg" class="input">&nbsp;<input name="upload" value="Upload" type="submit" ></td> 
     </tr> 
    </table>  
    </form> 
    </div> 
    <br> 
    </td> 
    </tr> 
    <tr style="font-size:12px;"> 
     <td class="list_title" align="center" style="padding:15px;"> 
     <form action="add_category.asp" method="post" id="addCategory"> 
     <span><b>NEW CATEGORY:</b></span>&nbsp; 
     <input name="cat" type="text" style="width:140; font-size:12px;"> 
     <input name="" type="submit" value="ADD" style="font-size:10px;"> 
     </form> 
     </td> 
    <td class="list_title" align="center" style="padding:15px;"> 
     <form action="delete_category.asp" method="post" id="deleteCategory"> 
     <span><b>DELETE CATEGORY:&nbsp;</b></span> 
     <select name="cat" style="font-size:12px; width:130px; height:19px;"> 
     <option selected>-- select --</option> 
     <% 
        set fo=fs.GetFolder(Server.MapPath("images/gallery")) 
        for each x in fo.SubFolders 
         Response.write("<option value='" & x.Name & "'>" & x.Name & "</option>") 
        next 
       %> 
     </select> 
     <input type="button" value="REMOVE" style="font-size:10px;" onClick="javascript:ConfirmFormChoice('Are you sure you wish to delete this category and all of its contents?','deleteCategory');"> 
     </form> 
    </td> 
    </tr> 

</table> 
<%else%> 
<table width="700" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
    <td align="center" style="padding-left:30px"> 

    <div style="float:none;">  
     <%if cat <> "" and fs.FolderExists(Server.MapPath("images/gallery/" & cat)) then 
     set fo=fs.GetFolder(Server.MapPath("images/gallery/" & cat)) 
     path = "images/gallery/" & cat 
     else 
     set fo=fs.GetFolder(Server.MapPath("images/gallery")) 
     path = "images/gallery" 
     end if 

     for each folder in fo.subfolders ' display categorises 
     isSub = false%> 
     <a href="album.asp?cat=<%=encrypt(folder.Name)%>" style="text-decoration:none; cursor:pointer;"> 
      <div class="text" style="width:90px; height:120px;background-image:url(images/layout/folder.jpg); background-repeat:no-repeat; float:left; text-align:center;"><br /><br /> 
      <%set fi=fs.GetFolder(Server.MapPath("images/gallery/" & folder.Name)) 
      for each file in fi.files 
       if right(lcase(file.Name),3) = "jpg" then%> 
       <br><img src="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & folder.Name & "/" & file.Name)%>&maxWidth=40&maxHeight=30" style="border:1px solid #ffffff; cursor:default;" /><% 
       exit for 
       end if 
      next 
      %><br><br><span style="font-size:9px; font-weight:normal; color:#000"><%=folder.Name%></span></div> 
     </a>   
     <%next%> 
     </div> 
      </td> 
    </tr> 
    <tr> 
    <td align="center" style="padding-left:30px;"> 
<br /> 
    <hr noshade="noshade" size="1px" color="#ffb883" width="400px" /> 
     <%for each file in fo.files ' display uncategorized pics 
     if right(lcase(file.Name),3) = "jpg" then%> 
      <a href="thumbnail.aspx?picture=<%=server.URLEncode(path & "/" & file.Name)%>&maxWidth=640&maxHeight=480" target="_blank" style="text-decoration:none; cursor:pointer;"> 
      <img src="thumbnail.aspx?picture=<%=server.URLEncode(path & "/" & file.Name)%>&maxWidth=160&maxHeight=100" style="border:1px solid #ffffff; margin:5px; margin-top:14px;"> 
      </a>   
     <%end if 
     next%> 
     <br /><br /> 
     <%if isSub then%> 
     <hr noshade="noshade" size="1px" color="#ffb883" width="400px" /> 
     <div align="center" style="padding-left:20px;"><a href="album.asp" class="title" style="text-decoration:none; cursor:pointer; font-weight:bold; font-size:10px">BACK TO MAIN ALBUM</a></div> 
     <%end if%> 
    </td> 
    </tr> 
</table> 
<%end if%> 
<!-- #INCLUDE file="layout_bottom.asp" --> 
</body> 
</html> 

BELOW編碼爲FILE_UPLOAD.ASP編碼

<% 
Option Explicit 

' used to track various positions 
dim PosB, PosBBound, PosEBound, PosEHead, PosBFld, PosEFld 

' these handle the data 
dim Boundary, BBoundary, PartBHeader, PartAHeader, PartContent, PartContent2, Binary 

' for writing and converting 
dim fso, fle, rst, DataString, FileName 

' various other 
dim I, Length, ContType, PartName, LastPart, BCrlf, PartContentLength 
dim MaxWidth, MaxHeight, NewFileName, FilePath, AcceptedFiles, Redirect, Extension, SavedFileName, Image, NewHeight, otherExtension 

Session.Timeout = 30 
'Allow 300 seconds for file to upload 
Server.ScriptTimeout = 300 

MaxWidth  = CINT(Request.QueryString("MaxWidth")) 
MaxHeight  = CINT(Request.QueryString("MaxHeight")) 
NewFileName = Request.QueryString("FileName") 
FilePath  = Request.QueryString("FilePath") 
AcceptedFiles = Request.QueryString("AcceptedFiles") 
Redirect  = Request.QueryString("Redirect") 

' ado constants 
const adLongVarBinary = 205 
const adLongVarchar = 201 

' must be submitted using POST 
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then 

    ContType = Request.ServerVariables("HTTP_Content_Type") 
    ' must be "multipart/form-data" 
    If LCase(Left(ContType, 19)) = "multipart/form-data" Then 
     PosB = InStr(LCase(ContType), "boundary=") 'get boundary 
     If PosB > 0 Then Boundary = Mid(ContType, PosB + 9) 'we have one 

     'bugfix IE5.01 - double header 
     PosB = InStr(LCase(ContType), "boundary=") 
     If PosB > 0 then 
      PosB = InStr(Boundary, ",") 
      If PosB > 0 Then Boundary = Left(Boundary, PosB - 1) 
     End If 

     Length = CLng(Request.ServerVariables("HTTP_Content_Length")) 'Get Content-Length header 
    End If 

    If Length > 0 And Boundary <> "" Then 
     Boundary = "--" & Boundary 

     ' get request, binary 
     Binary = Request.BinaryRead(Length) 

     ' convert boundry to binary 
     For I=1 to len(Boundary) 
      BBoundary = BBoundary & ChrB(Asc(Mid(Boundary,I,1))) 
     Next 

     ' binary crlf 
     BCrlf = ChrB(Asc(vbCr)) & ChrB(Asc(vbLf)) 

     ' get begin and end of first boundary 
     PosBBound = InStrB(Binary, BBoundary) 
     PosEBound = InStrB(PosBBound + LenB(BBoundary), Binary, BBoundary, 0) 

     ' keep doing until we had them all 
     Do While (PosBBound > 0 And PosEBound > 0) 

      ' get position of the end of the header 
      PosEHead = InStrB(PosBBound + LenB(BBoundary), Binary, BCrlf & BCrlf) 

      ' get content of header and convert to string 
      PartBHeader = MidB(Binary, PosBBound + LenB(BBoundary) + 2, PosEHead - PosBBound - LenB(BBoundary) - 2) 
      PartAHeader = "" 
      For I=1 to lenb(PartBHeader) 
       PartAHeader = PartAHeader & Chr(AscB(MidB(PartBHeader,I,1))) 
      Next 

      ' make sure we end it with ; 
      If Right(PartAHeader,1) <> ";" Then PartAHeader = PartAHeader & ";" 

      ' get content of this part 
      PartContent = MidB(Binary, PosEHead + 4, PosEBound - (PosEHead + 4) - 2) 

      ' get name of part 
      PosBFld = Instr(lcase(PartAHeader),"name=") 
      If PosBFld > 0 Then 
       ' name found 
       PosEFld = Instr(PosBFld,lcase(PartAHeader),";") 
       If PosEFld > 0 Then 
        ' well-formed name header 
        PartName = Mid(PartAHeader,PosBFld+5,PosEFld-PosBFld-5) 
       End If 
       ' chop of leading and trailing "'s 
       Do Until Left(PartName,1) <> """" 
        PartName = Mid(PartName,2) 
       Loop 
       Do Until Right(PartName,1) <> """" 
        PartName = Left(PartName,Len(PartName)-1) 
       Loop 
      End If 

      ' get file name of part (if any) 
      PosBFld = Instr(lcase(PartAHeader),"filename=""") 
      If PosBFld > 0 Then 
       ' content header found 
       PosEFld = Instr(PosBFld + 10,lcase(PartAHeader),"""") 
       If PosEFld > 0 Then 
        ' well-formed content header 
        FileName = Mid(PartAHeader,PosBFld+10,PosEFld-PosBFld-10) 
       End If 
       ' chop of leading and trailing "'s 
       Do Until Left(FileName,1) <> """" 
        FileName = Mid(FileName,2) 
       Loop 
       Do Until Right(FileName,1) <> """" 
        FileName = Left(FileName,Len(FileName)-1) 
       Loop 
      Else 
       FileName = "" 
      End If 

      ' ikkonverti minn binary ghal data regolari 

      ' at the end, datastring will contain 'readable' data 
      ' is this wide-byte binary data? 
      if vartype(PartContent) = 8 then 
       ' need to do some conversion 
       Set rst = CreateObject("ADODB.Recordset") 
       PartContentLength = LenB(PartContent) 
       if PartContentLength > 0 then 
        ' data, so add to recordset to speed up conversion 
        rst.Fields.Append "data", adLongVarBinary, PartContentLength 
        rst.Open 
        rst.AddNew 
        rst("data").AppendChunk PartContent & ChrB(0) 
        rst.Update 
        PartContent2 = rst("data").GetChunk(PartContentLength) 
        rst.close 
        set rst = nothing 
       else 
        ' no data? 
        PartContent2 = ChrB(0) 
       End If 
      Else 
       ' no need for conversion 
       PartContent2 = PartContent 
      End If 

      PartContentLength = LenB(PartContent2) 
      if PartContentLength > 0 then 
       ' we have data to convert 
       Set rst = CreateObject("ADODB.Recordset") 
       rst.Fields.Append "data", adLongVarChar, PartContentLength 
       rst.Open 
       rst.AddNew 
       rst("data").AppendChunk PartContent2 
       rst.Update 
       DataString = rst("data") 
       rst.close 
       set rst = nothing 
      Else 
       ' nothing to convert 
       dataString = "" 
      End If 

      ' conversion has been done, now what to do with it 
      If FileName <> "" Then 
       ' we have a file, let's save it to disk 
       FileName = Mid(Filename,InstrRev(FileName,"\")+1) 
       Extension = UCASE(Mid(Filename,InstrRev(FileName,".")+1)) 
     '  response.Write(Extension) 
       IF AcceptedFiles <> "" THEN 
        'Check if file is acceptable 
        IF INSTR(1, UCASE(AcceptedFiles), Extension) = 0 THEN 
       Response.redirect(redirect & "&formatError=true") 
       Response.End 
        End If 
       End IF 

       If NewFileName = "" THEN 
        'l-isem tal-file jibqa l-istess/differend extension 
        NewFileName = replace(lcase(FileName),"." & lcase(extension),".jpg") 
       END IF 
      ' response.Write(NewFileName) 
'    response.end 
       IF FilePath <> "" THEN 
        IF RIGHT(FilePath,1) <> "\" THEN Filepath = FilePath & "\" 
       END IF 
       SavedFileName = FilePath & NewFileName 
      ' response.Write(savedfilename) 
       ' iftah il-file (textstream) 
       set fso = Server.CreateObject("Scripting.Filesystemobject") 
       set fle = fso.CreateTextFile(Server.MapPath(SavedFileName & "." & lcase(extension))) 

       ' write the data 
       fle.write DataString 
       fle.close 
       ' cleanup 
       set fle = nothing 
       set fso = nothing     
      End If 

      'remove other type of file if exists-------------------- 

'   if lcase(extension) = "jpg" then 
'    otherExtension = "pdf" 
'   elseif lcase(extension) = "pdf" then 
'    otherExtension = "jpg" 
'   end if 
'   
'   dim fs 
'   dim f 
'   set fs=Server.CreateObject("Scripting.FileSystemObject") 
'   if fs.FileExists(Server.MapPath(SavedFileName & "." & otherExtension))=true then 
'    set f=fs.GetFile(Server.MapPath(SavedFileName & "." & otherExtension))   
'    f.delete 
'   end if 
'   
'   set fs = nothing 
'   set f = nothing 

      '------------------------------ 


      LastPart = MidB(Binary, PosEBound + LenB(BBoundary), 2) 

      If LastPart = ChrB(Asc("-")) & ChrB(Asc("-")) Then 
       ' don't look for others 
       PosBBound = 0 
       PosEBound = 0 
      ELSE 
       ' look for others 
       PosBBound = PosEBound 
       PosEBound = InStrB(PosBBound + LenB(BBoundary), Binary, BBoundary) 
      End If 

     loop 
    ELSE 
    ' Response.Write "<P>Invalid or empty request, no fields processed. Make sure that the content type is multipart/form-data" 
     Response.End 
    End If 
ELSE 
' Response.Write "<P>Form must be submitted using the POST method" 
    Response.End 
End If 

'Response.Write "<BR>Execution ended: " & Now & "<BR>" 
'Response.Write "Filename = " & SavedFileName & "<BR>" 
'Response.Write "MaxWidth = " & MaxWidth  & "<BR>" 
'Response.Write "MaxHeight = " & MaxHeight  & "<BR>" 

'///Biddel id-daqs tal-istampa jekk tkun akbar minn kemm suppost/// 
'IF MaxHeight > 0 AND MaxWidth > 0 THEN 
' Set Image = Server.CreateObject("csImageFile.Manage") 
' Image.ReadFile Server.MapPath(SavedFileName) 
' IF Image.Height > MaxHeight OR Image.Width > MaxWidth THEN 
'  NewHeight = ((Image.Height/Image.Width) * MaxWidth) 
'  IF NewHeight > MaxHeight THEN 
'   'Resizing Based On Height 
'   Image.Resize 0, MaxHeight 
'  ELSE 
'   'Resizing Based On Width 
'   Image.Resize MaxWidth, 0 
'  End If 
'  Image.JpegQuality = 85 
'  Image.WriteFile Server.MapPath(SavedFileName) 
' End If 
' Image.HasFileInfo = False 
' Set Image = Nothing 
'END IF 
'\\\\\\\\\\\\\\\\\\\\\\ 

IF Redirect <> "" AND lcase(extension) = "jpg" AND MaxWidth > 0 AND MaxHeight > 0 THEN 
Response.redirect "resize_picture.aspx?Picture=" & server.URLEncode(Server.MapPath(SavedFileName)) & "." & lcase(extension) & "&MaxWidth=" & server.URLEncode(maxWidth) & "&maxHeight=" & server.URLEncode(maxHeight) & "&Redirectto=" & server.URLEncode(Redirect) 
ELSEIF Redirect <> "" THEN 
Response.redirect(redirect) 
END IF 
%> 

誰能幫助我整合多個UPLOADS中提到的ABOVE FRAMEWORK :)?

回答

0

你試過用多個<input type="file">的嗎?

編輯:

你可以嘗試什麼也話,是動態創建,在它的文件輸入字段的IFRAME,並提交該表格,拿着文件在一個臨時位置的服務器上,並以某種方式向用戶指示他們已經上傳了一個文件。

+0

是的,我嘗試過,但只有1人上傳。 – Josmar 2009-11-03 16:07:39

0

也許一個基於Flash的上傳工具會更好。許多支持在單個頁面上進行多次上傳的網站正在轉向這種解決方案。

這裏有一對夫婦,一個Google search出土:

+0

感謝您的答覆... ,但我希望有一個多文件上傳系統(這是很容易在asp.net 2.0做) 但我需要可以實現上述系統具有多個上傳一些幫助.. 或找到另一個解決方案,我可以選擇要上傳的目錄以及調整/壓縮我上傳的圖片。 謝謝 – Josmar 2009-11-03 21:12:39

0

僅供參考,這些頁面都是經典的ASP和無關的多最近推出的ASP.NET技術。

我不知道如何解決您的問題,但很長一段時間以前,我已經使用市售的SoftArtisans FileUp component在經典ASP中允許可靠的多文件上傳。

+0

我知道編碼有點舊,但它是在我的朋友的空閒時間免費寫的... 但該網站是在一個Windows託管計劃和asp.net 2.0/3.5 .. 希望任何人都可以幫助我! – Josmar 2009-11-03 20:46:44