Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple Uploads
    text
    copied!<p>hey I need the help with the following. I have a website, altough I was not a 100% programmer, I am trying to navigate within the programming of the site. It work in asp.net 2.0.</p> <p>I have an image gallery, but the only problem is that I can only upload 1 image at a time. I need some help how i can integrate multiple images on the site.</p> <p><strong>below is the coding for album.asp</strong></p> <pre><code> &lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%&gt; &lt;!-- #INCLUDE file="inc/settings.asp" --&gt; &lt;!-- #INCLUDE file="inc/functions.asp" --&gt; &lt;!-- #INCLUDE file="inc/db_connect.asp" --&gt; &lt;!-- #INCLUDE file="inc/check_login.asp" --&gt; &lt;!--#INCLUDE file="fckeditor/fckeditor.asp" --&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;script type="text/javascript" src="js/script.js"&gt;&lt;/script&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Xaghra Scouts&lt;/title&gt; &lt;link href="styles.css" rel="stylesheet" type="text/css" /&gt; &lt;% cat = decrypt(request("cat") &amp; "") set fs=Server.CreateObject("Scripting.FileSystemObject") isSub = true %&gt; &lt;/head&gt; &lt;body&gt; &lt;!-- #INCLUDE file="layout_top.asp" --&gt; &lt;%if loggedin then%&gt; &lt;table align="center" border="0" cellspacing="0" cellpadding="5" class="main"&gt; &lt;tr &gt; &lt;td align="center" style="padding:15px;" colspan="2"&gt; &lt;form action="album.asp" method="post" id="selectCategory"&gt; &lt;b&gt;SELECT CATEGORY:&amp;nbsp;&lt;/b&gt; &lt;select name="cat" style="font-size:12px; width:160px; height:19px;" onChange="javascript: document.getElementById('selectCategory').submit();"&gt; &lt;option selected&gt;Uncategorized&lt;/option&gt; &lt;% set fo=fs.GetFolder(Server.MapPath("images/gallery")) for each x in fo.SubFolders Response.write("&lt;option value='" &amp; encrypt(x.Name) &amp; "'") if cat = x.Name then response.write("selected") end if Response.write("&gt;" &amp; x.Name &amp; "&lt;/option&gt;") next %&gt; &lt;/select&gt; &lt;/form&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="color:#666666; font-size:12px;"&gt; &lt;td colspan="2" align="left"&gt; &lt;br&gt; &lt;% if cat &lt;&gt; "" and fs.FolderExists(Server.MapPath("images/gallery/" &amp; cat)) then set fo=fs.GetFolder(Server.MapPath("images/gallery/" &amp; cat)) path = "gallery/" &amp; 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%&gt; &lt;div style="height:120px; width:160px; text-align:center; float:left;"&gt;&lt;img src="thumbnail.aspx?picture=&lt;%=server.URLEncode("images/" &amp; path &amp; "/" &amp; file.Name)%&gt;&amp;maxWidth=160&amp;maxHeight=100" style="border:1px solid #ffffff;"&gt;&lt;br&gt; &lt;a onClick="javascript:ConfirmChoice('Are you sure you wish to delete this picture?','delete_image.asp?cat=&lt;%=encrypt(cat)%&gt;&amp;file=&lt;%=Server.URLEncode("images/" &amp; path &amp; "/" &amp; file.Name)%&gt;');"href="#" style="font-size:10px"&gt;DELETE&lt;/a&gt;&lt;/div&gt; &lt;%end if next %&gt; &lt;/tr&gt; &lt;tr style="color:#666666; font-size:12px;"&gt; &lt;td colspan="2" align="left"&gt; &lt;div style="text-align:center;"&gt; &lt;form action="file_upload.asp?FileName=&lt;%=Server.URLEncode(uniqueName())%&gt;&amp;FilePath=&lt;%=Server.URLEncode("images/" &amp; path)%&gt;&amp;AcceptedFiles=&lt;%=Server.URLEncode("JPG")%&gt;&amp;Redirect=&lt;%=Server.URLEncode("album.asp")%&gt;&amp;MaxHeight=480&amp;MaxWidth=640" enctype="multipart/form-data" method="post"&gt; &lt;table align="center" border="0" cellspacing="0" cellpadding="20" class="main"&gt; &lt;tr&gt; &lt;td align="center" class="details"&gt; &lt;div style="color:#FF0000; font-size:10px;"&gt;&lt;%if (request.QueryString("formatError") &amp; "") &lt;&gt; "" then%&gt;INVALID FILE FORMAT ( .JPG ONLY )&lt;%end if%&gt;&amp;nbsp;&lt;/div&gt;&lt;br&gt; &lt;input name="file" type="file" accept="jpg/jpeg" class="input"&gt;&amp;nbsp;&lt;input name="upload" value="Upload" type="submit" &gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/div&gt; &lt;br&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr style="font-size:12px;"&gt; &lt;td class="list_title" align="center" style="padding:15px;"&gt; &lt;form action="add_category.asp" method="post" id="addCategory"&gt; &lt;span&gt;&lt;b&gt;NEW CATEGORY:&lt;/b&gt;&lt;/span&gt;&amp;nbsp; &lt;input name="cat" type="text" style="width:140; font-size:12px;"&gt; &lt;input name="" type="submit" value="ADD" style="font-size:10px;"&gt; &lt;/form&gt; &lt;/td&gt; &lt;td class="list_title" align="center" style="padding:15px;"&gt; &lt;form action="delete_category.asp" method="post" id="deleteCategory"&gt; &lt;span&gt;&lt;b&gt;DELETE CATEGORY:&amp;nbsp;&lt;/b&gt;&lt;/span&gt; &lt;select name="cat" style="font-size:12px; width:130px; height:19px;"&gt; &lt;option selected&gt;-- select --&lt;/option&gt; &lt;% set fo=fs.GetFolder(Server.MapPath("images/gallery")) for each x in fo.SubFolders Response.write("&lt;option value='" &amp; x.Name &amp; "'&gt;" &amp; x.Name &amp; "&lt;/option&gt;") next %&gt; &lt;/select&gt; &lt;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');"&gt; &lt;/form&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;%else%&gt; &lt;table width="700" border="0" cellspacing="0" cellpadding="0"&gt; &lt;tr&gt; &lt;td align="center" style="padding-left:30px"&gt; &lt;div style="float:none;"&gt; &lt;%if cat &lt;&gt; "" and fs.FolderExists(Server.MapPath("images/gallery/" &amp; cat)) then set fo=fs.GetFolder(Server.MapPath("images/gallery/" &amp; cat)) path = "images/gallery/" &amp; 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%&gt; &lt;a href="album.asp?cat=&lt;%=encrypt(folder.Name)%&gt;" style="text-decoration:none; cursor:pointer;"&gt; &lt;div class="text" style="width:90px; height:120px;background-image:url(images/layout/folder.jpg); background-repeat:no-repeat; float:left; text-align:center;"&gt;&lt;br /&gt;&lt;br /&gt; &lt;%set fi=fs.GetFolder(Server.MapPath("images/gallery/" &amp; folder.Name)) for each file in fi.files if right(lcase(file.Name),3) = "jpg" then%&gt; &lt;br&gt;&lt;img src="thumbnail.aspx?picture=&lt;%=server.URLEncode("images/gallery/" &amp; folder.Name &amp; "/" &amp; file.Name)%&gt;&amp;maxWidth=40&amp;maxHeight=30" style="border:1px solid #ffffff; cursor:default;" /&gt;&lt;% exit for end if next %&gt;&lt;br&gt;&lt;br&gt;&lt;span style="font-size:9px; font-weight:normal; color:#000"&gt;&lt;%=folder.Name%&gt;&lt;/span&gt;&lt;/div&gt; &lt;/a&gt; &lt;%next%&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="center" style="padding-left:30px;"&gt; &lt;br /&gt; &lt;hr noshade="noshade" size="1px" color="#ffb883" width="400px" /&gt; &lt;%for each file in fo.files ' display uncategorized pics if right(lcase(file.Name),3) = "jpg" then%&gt; &lt;a href="thumbnail.aspx?picture=&lt;%=server.URLEncode(path &amp; "/" &amp; file.Name)%&gt;&amp;maxWidth=640&amp;maxHeight=480" target="_blank" style="text-decoration:none; cursor:pointer;"&gt; &lt;img src="thumbnail.aspx?picture=&lt;%=server.URLEncode(path &amp; "/" &amp; file.Name)%&gt;&amp;maxWidth=160&amp;maxHeight=100" style="border:1px solid #ffffff; margin:5px; margin-top:14px;"&gt; &lt;/a&gt; &lt;%end if next%&gt; &lt;br /&gt;&lt;br /&gt; &lt;%if isSub then%&gt; &lt;hr noshade="noshade" size="1px" color="#ffb883" width="400px" /&gt; &lt;div align="center" style="padding-left:20px;"&gt;&lt;a href="album.asp" class="title" style="text-decoration:none; cursor:pointer; font-weight:bold; font-size:10px"&gt;BACK TO MAIN ALBUM&lt;/a&gt;&lt;/div&gt; &lt;%end if%&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;%end if%&gt; &lt;!-- #INCLUDE file="layout_bottom.asp" --&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>BELOW IS THE CODING FOR FILE_UPLOAD.ASP</strong></p> <pre><code>&lt;% 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 &gt; 0 Then Boundary = Mid(ContType, PosB + 9) 'we have one 'bugfix IE5.01 - double header PosB = InStr(LCase(ContType), "boundary=") If PosB &gt; 0 then PosB = InStr(Boundary, ",") If PosB &gt; 0 Then Boundary = Left(Boundary, PosB - 1) End If Length = CLng(Request.ServerVariables("HTTP_Content_Length")) 'Get Content-Length header End If If Length &gt; 0 And Boundary &lt;&gt; "" Then Boundary = "--" &amp; Boundary ' get request, binary Binary = Request.BinaryRead(Length) ' convert boundry to binary For I=1 to len(Boundary) BBoundary = BBoundary &amp; ChrB(Asc(Mid(Boundary,I,1))) Next ' binary crlf BCrlf = ChrB(Asc(vbCr)) &amp; 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 &gt; 0 And PosEBound &gt; 0) ' get position of the end of the header PosEHead = InStrB(PosBBound + LenB(BBoundary), Binary, BCrlf &amp; 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 &amp; Chr(AscB(MidB(PartBHeader,I,1))) Next ' make sure we end it with ; If Right(PartAHeader,1) &lt;&gt; ";" Then PartAHeader = PartAHeader &amp; ";" ' 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 &gt; 0 Then ' name found PosEFld = Instr(PosBFld,lcase(PartAHeader),";") If PosEFld &gt; 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) &lt;&gt; """" PartName = Mid(PartName,2) Loop Do Until Right(PartName,1) &lt;&gt; """" PartName = Left(PartName,Len(PartName)-1) Loop End If ' get file name of part (if any) PosBFld = Instr(lcase(PartAHeader),"filename=""") If PosBFld &gt; 0 Then ' content header found PosEFld = Instr(PosBFld + 10,lcase(PartAHeader),"""") If PosEFld &gt; 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) &lt;&gt; """" FileName = Mid(FileName,2) Loop Do Until Right(FileName,1) &lt;&gt; """" 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 &gt; 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 &amp; 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 &gt; 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 &lt;&gt; "" 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 &lt;&gt; "" THEN 'Check if file is acceptable IF INSTR(1, UCASE(AcceptedFiles), Extension) = 0 THEN Response.redirect(redirect &amp; "&amp;formatError=true") Response.End End If End IF If NewFileName = "" THEN 'l-isem tal-file jibqa l-istess / differend extension NewFileName = replace(lcase(FileName),"." &amp; lcase(extension),".jpg") END IF ' response.Write(NewFileName) ' response.end IF FilePath &lt;&gt; "" THEN IF RIGHT(FilePath,1) &lt;&gt; "\" THEN Filepath = FilePath &amp; "\" END IF SavedFileName = FilePath &amp; NewFileName ' response.Write(savedfilename) ' iftah il-file (textstream) set fso = Server.CreateObject("Scripting.Filesystemobject") set fle = fso.CreateTextFile(Server.MapPath(SavedFileName &amp; "." &amp; 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 &amp; "." &amp; otherExtension))=true then ' set f=fs.GetFile(Server.MapPath(SavedFileName &amp; "." &amp; otherExtension)) ' f.delete ' end if ' ' set fs = nothing ' set f = nothing '------------------------------ LastPart = MidB(Binary, PosEBound + LenB(BBoundary), 2) If LastPart = ChrB(Asc("-")) &amp; 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 "&lt;P&gt;Invalid or empty request, no fields processed. Make sure that the content type is multipart/form-data" Response.End End If ELSE ' Response.Write "&lt;P&gt;Form must be submitted using the POST method" Response.End End If 'Response.Write "&lt;BR&gt;Execution ended: " &amp; Now &amp; "&lt;BR&gt;" 'Response.Write "Filename = " &amp; SavedFileName &amp; "&lt;BR&gt;" 'Response.Write "MaxWidth = " &amp; MaxWidth &amp; "&lt;BR&gt;" 'Response.Write "MaxHeight = " &amp; MaxHeight &amp; "&lt;BR&gt;" '///Biddel id-daqs tal-istampa jekk tkun akbar minn kemm suppost/// 'IF MaxHeight &gt; 0 AND MaxWidth &gt; 0 THEN ' Set Image = Server.CreateObject("csImageFile.Manage") ' Image.ReadFile Server.MapPath(SavedFileName) ' IF Image.Height &gt; MaxHeight OR Image.Width &gt; MaxWidth THEN ' NewHeight = ((Image.Height/Image.Width) * MaxWidth) ' IF NewHeight &gt; 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 &lt;&gt; "" AND lcase(extension) = "jpg" AND MaxWidth &gt; 0 AND MaxHeight &gt; 0 THEN Response.redirect "resize_picture.aspx?Picture=" &amp; server.URLEncode(Server.MapPath(SavedFileName)) &amp; "." &amp; lcase(extension) &amp; "&amp;MaxWidth=" &amp; server.URLEncode(maxWidth) &amp; "&amp;maxHeight=" &amp; server.URLEncode(maxHeight) &amp; "&amp;Redirectto=" &amp; server.URLEncode(Redirect) ELSEIF Redirect &lt;&gt; "" THEN Response.redirect(redirect) END IF %&gt; </code></pre> <p><strong>CAN ANYONE HELP ME INTEGRATE MULTIPLE UPLOADS IN THE ABOVE MENTIONED FRAMEWORK :) ?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload