I have as ASP page, this page reads a xml file and shows the information inside a table.
I need to create a second script just like the first one to read a second xml file and display the info in another table.
i created the script, that i will post below, the page take ages to load, and only the first script loads.
<div class="centro">
<table class="tabela_centro">
<tr>
<td class="td_noticias_barra_vertical"></td>
<td class="td_noticias_toda"
<%
response.write (" style=width:950px !important; "" >")
%>
<div class="noticias">
<%
'--------------------------------------ver quantas noticias estao activas
'
dim qt_noticias_activas
qt_noticias_activas=0
dim array_noticias_activas()
dim activo
Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load("c:\temp\noticias.xml")
for i=1 to 10
Set itemList = XMLDom.SelectNodes("noticias/noticia" & i)
For Each itemAttrib In itemList
activo =itemAttrib.SelectSingleNode("activo").text
if activo="S" then
redim preserve array_noticias_activas(qt_noticias_activas)
array_noticias_activas(qt_noticias_activas)=i
qt_noticias_activas=qt_noticias_activas+1
end if
' response.write activo
Next
' response.write i & "-" & qt_noticias_activas & "-" & array_noticias_activas(0)
next
'---------------------------------------------ver qual o minuto actual
'
dim minutos
minutos=minute(now)+60
' ----------------------------------------descobrir qual noticia a mostrar
'
dim noticia_a_mostrar
while minutos > qt_noticias_activas
minutos=minutos - qt_noticias_activas
wend
noticia_a_mostrar=array_noticias_activas(minutos -1)
'-----------------------------------------------------carregar a noticia escolhida
'
dim titulo, data, texto, foto1, foto2
Set itemList = XMLDom.SelectNodes("noticias/noticia" & noticia_a_mostrar)
For Each itemAttrib In itemList
data =itemAttrib.SelectSingleNode("data").text
titulo =itemAttrib.SelectSingleNode("titulo").text
foto1 =itemAttrib.SelectSingleNode("foto1").text
foto2 =itemAttrib.SelectSingleNode("foto2").text
Next
Set xmlDOM = Nothing
Set itemList = Nothing
'response.write titulo & data & foto1 & foto2
'
%>
<table>
<tr>
<td colspan="2">
<div class="noticias_titulo">
<%=titulo%>
</div>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr class="tr_noticias_fotos">
<td class="td_noticias_fotos1">
<div class="noticias_foto1">
<img class="foto1" src="<%=foto1%>">
</div>
</td>
<td class="td_noticias_fotos2">
<div class="noticias_foto2">
<img class="foto2" src="<%=foto2%>">
</div>
</td>
</tr>
</table>
</div>
</td>
<td class="td_servicos_barra_vertical"></td>
<td style="max-width:35%; vertical-align:top;" class="td_servicos_toda">
<div id="secstate">
<div><h3 class="cultura_titulo">Estado de segurança: <span id="span_estado">ALFA<span></h3></div>
</div>
<%
'--------------------------------------ver quantas noticias culturais estao activas
'
dim qt_culturas_activas
qt_culturas_activas=0
dim array_culturas_activas()
dim activocult
Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load("c:\temp\culturas.xml")
for i=1 to 10
Set itemList = XMLDom.SelectNodes("culturas/cultura" & i)
For Each itemAttrib In itemList
activocult =itemAttrib.SelectSingleNode("activo").text
if activo="S" then
redim preserve array_culturas_activas(qt_culturas_activas)
array_culturas_activas(qt_culturas_activas)=i
qt_culturas_activas=qt_culturas_activas+1
end if
' response.write activocult
Next
' response.write i & "-" & qt_culturas_activas & "-" & array_culturas_activas(0)
next
'---------------------------------------------ver qual o minuto actual
'
dim minutoscult
minutoscult=minute(now)+60
' ----------------------------------------descobrir qual noticia de cultura a mostrar
'
dim cultura_a_mostrar
while minutoscult > qt_culturas_activas
minutoscult=minutoscult - qt_culturas_activas
wend
cultura_a_mostrar=array_culturas_activas(minutoscult -1)
'-----------------------------------------------------carregar a noticia de cultura escolhida
'
dim titulocult, datacult, foto1cult
Set itemList = XMLDom.SelectNodes("culturas/cultura" & cultura_a_mostrar)
For Each itemAttrib In itemList
datacult =itemAttrib.SelectSingleNode("data").text
titulocult =itemAttrib.SelectSingleNode("titulo").text
foto1cult =itemAttrib.SelectSingleNode("foto1").text
Next
Set xmlDOM = Nothing
Set itemList = Nothing
'response.write titulocult & datacult & foto1cult
'
%>
<div class="cultura_titulo"><h4><%=titulocult%></h4></div>
<div class="cultura_foto">
<img style="width:90%" src="<%=foto1cult%>">
</div>
</td>
</tr>
</table><!--fim da tabela do centro todo -->
</div>
Can you guys help me out a bit? i was asked to complete another developer job... and i am not really inside the ASP language.
Regards
roberto
Ok, i have found my mistake, in the line if activo="S" then of the second script, it should be if activocult="S" then.
thanks for your time
I want to add a class for Masonry in the loop while.
What can I do for loop should be only one?
Is output to the three data three times.
Is there another way?
<div id="box-container">
<div class="grid-sizer"><!-- avl for packery to get grid size --></div>
<%
'creates an array
Dim x, y, z
x = Array("w2 h1", "w1 h2", "w1 h1")
rso()
cate = "fo01"
SQL = " SELECT TOP 3 * FROM ms_dbtable WHERE category = '"& cate &"' ORDER BY sort_idx ASC "
rs.open SQL, dbcon, 3
If Not rs.eof Then
While Not rs.EOF
For Each y In x
%>
<div class='box snip1328 <%=y%>'>
<% If rs("thumb") = "" Then %>
<img src="/img/tlogo.gif"></a>
<% Else %>
<img src="/data/fo01/<%=rs("thumb")%>"></a>
<% End If %>
</div>
<%
Next
%>
<%
rs.MoveNext
Wend
End If
rsc()
%>
<style>
.w1 {width: 138px;}
.h1 {height: 138px;}
.w2 {width: 280px;}
.h2 {height: 280px;}
.w3 {width: 422px;}
.h3 {height: 422px;}
</style>
The result is output as a duplicate image.
The output data has Blurring the face picture.
enter image description here
Since you are selecting TOP 3, and there are three elements in the array,
you could move the array index within the loop using a counter.
If Not rs.eof Then
Dim xindex : xindex=0
While Not rs.EOF
%>
<div class='box snip1328 <%=x(xindex)%>'>
<% If rs("thumb") = "" Then %>
<img src="/img/tlogo.gif"></a>
<% Else %>
<img src="/data/fo01/<%=rs("thumb")%>"></a>
<% End If %>
</div>
<%
xindex = xindex + 1
rs.MoveNext
Wend
End If
I'm trying to loop through a table to see if a check box is checked. On button click SendCheckEmail is called. I'm getting an error EmailForm is not declared and also I'm unsure of how to loop through the table to process each checkbox that is checked.
Sub Page_Load
If Request.QueryString("show") <> "" then
dim Sr as StreamReader = New StreamReader("d:\netdrvs\prs\emaillist\" & Request.QueryString("show"),FileMode.Open)
output="<table id=EmailForm border=1 padding=4 >" & VBCR
output+="<tr><td>Customer Code</td><td>Email</td><td>Invoice Number</td><td>Regarding</td><td> <input type=checkbox name=chkHeader id=chkHeader></td></tr>"
While Not SR.EndOfStream
dim Temp(3) as String
Temp = Split(SR.ReadLine(),vbTab)
dim temp2(3) as String
Temp2 = Split(Temp(0),"_")
output += "<tr>" & VBCR
output += "<td>" & Temp2(1) & "</td>" & VBCR
output += "<td>" & Temp(1) & "</td>" & VBCR
output += "<td>" & Temp2(0) & "</td>" & VBCR
output += "<td>" & Temp(2) & "</td>" & VBCR
output += "<td> <input type=checkbox name=chkRow id=chkRow> </td>" & VBCR
output += "</tr>"& VBCR
End While
output+="</table>" & VBCR
SR.Close()
ProcessChk.Visible = True
end if
End Sub
Sub SendCheckEmail (sender As Object, e As System.EventArgs)
Dim item
For each item in EmailForm
'loop through each row
NEXT
End Sub
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Lathams Invoice Email Sending</title>
<script type="text/javascript" src="ajax.googleapis.js"></script>
<script type="text/javascript">
$("[id*=chkHeader]").live("click", function () {
var chkHeader = $(this);
var grid = $(this).closest("table");
$("input[type=checkbox]", grid).each(function () {
if (chkHeader.is(":checked")) {
$(this).attr("checked", "checked");
$("td", $(this).closest("tr")).addClass("selected");
} else {
$(this).removeAttr("checked");
$("td", $(this).closest("tr")).removeClass("selected");
}
});
});
$("[id*=chkRow]").live("click", function () {
var grid = $(this).closest("table");
var chkHeader = $("[id*=chkHeader]", grid);
if (!$(this).is(":checked")) {
$("td", $(this).closest("tr")).removeClass("selected");
chkHeader.removeAttr("checked");
} else {
$("td", $(this).closest("tr")).addClass("selected");
if ($("[id*=chkRow]", grid).length == $("[id*=chkRow]:checked", grid).length) {
chkHeader.attr("checked", "checked");
}
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:label id="test" runat="server" />
<%=output%>
<p> </p>
<asp:Button id="ProcessFile" visible="false" runat="server" Text="Process Emails" onClick="SendMails" />
<asp:Button id="ProcessChk" visible="false" runat="server" Text="Process Checked Emails" OnClick="SendCheckEmail" />
</form>
</body>
</html>
set runat="server" to EmailForm
and then
IN C#
foreach (var item in tbl.Rows)
{
HtmlTableRow row = (HtmlTableRow)item;
foreach (var item1 in row.Controls)
{
HtmlTableCell cell = (HtmlTableCell)item1;
}
}
In VB.NET
Dim rowitem
Dim cellitem
For Each rowitem In tbl.Rows
HtmlTableRow row = (HtmlTableRow)rowitem;
For Each cellitem In tbl.Rows
HtmlTableCell cell = (HtmlTableCell)cellitem;
// cell items
next
next
// can directly access checkbox if it is set to runat='server'
EmailForm is not a a server control, so you cannot access it in CodeBehind.
You could try using a repeater or a table control that you bind to the file contents.
Otherwise you could add the email address as value attribute in the input tag.
output += " " & VBCR
Then you will receive a comma separated list of email addresses by accessing Request("chkRow")
Hey all, i have this peice of code that allows a user to select a jpg image, resize it and uploads it to the server driectory. The problem being is that it reloads the aspx page when it saves the image.
My question is-is there any way to do this same thing but with ajax so that it doesn't leave the page after submitting it? I've done this pleanty of times with classic asp pages but never with a aspx page.
Here is the code for the ASPX page:
<%# Page Trace="False" Language="vb" aspcompat="false" debug="true" validateRequest="false"%>
<%# Import Namespace=System.Drawing %>
<%# Import Namespace=System.Drawing.Imaging %>
<%# Import Namespace=System.Drawing.Text %>
<%# Import Namespace=System %>
<%# Import Namespace=System.IO %>
<%# Import Namespace=System.Web %>
<%# Import Namespace=System.ServiceProcess %>
<%# Import Namespace=Microsoft.Data.Odbc %>
<%# Import Namespace=System.Data.Odbc %>
<%# Import Namespace=MySql.Data.MySqlClient %>
<%# Import Namespace=MySql.Data %>
<%# Import Namespace=System.Drawing.Drawing2D %>
<%# Import Namespace="System.Data" %>
<%# Import Namespace="System.Data.ADO" %>
<%# Import Namespace=ADODB %>
<SCRIPT LANGUAGE="VBScript" runat="server">
const Lx = 200
const Ly = 60
const upload_dir = "/img/avatar/"
const upload_original = "tmpAvatar"
const upload_thumb = "thumb"
const upload_max_size = 256
dim fileExt
dim newWidth, newHeight as integer
dim l2
dim fileFld as HTTPPostedFile
Dim originalimg As System.Drawing.Image
dim msg
dim upload_ok as boolean
</script>
<%
Dim theID, theEmail, maleOrFemale
theID = Request.QueryString("ID")
theEmail = Request.QueryString("eMail")
maleOrFemale = Request.QueryString("MF")
randomize()
upload_ok = false
if lcase(Request.ServerVariables("REQUEST_METHOD"))="post" then
fileFld = request.files(0)
if fileFld.ContentLength > upload_max_size * 1024 then
msg = "Sorry, the image must be less than " & upload_max_size & "Kb"
else
try
fileExt = System.IO.Path.GetExtension(fileFld.FileName).ToLower()
if fileExt = ".jpg" then
originalImg = System.Drawing.Image.FromStream(fileFld.InputStream)
if originalImg.Height > Ly then
newWidth = Ly * (originalImg.Width / originalImg.Height)
newHeight = Ly
end if
Dim thumb As New Bitmap(newWidth, newHeight)
Dim gr_dest As Graphics = Graphics.FromImage(thumb)
dim sb = new SolidBrush(System.Drawing.Color.White)
gr_dest.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
gr_dest.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
gr_dest.FillRectangle(sb, 0, 0, thumb.Width, thumb.Height)
gr_dest.DrawImage(originalImg, 0, 0, thumb.Width, thumb.Height)
try
originalImg.save(Server.MapPath(upload_dir & upload_original & fileExt), originalImg.rawformat)
thumb.save(Server.MapPath(upload_dir & theID & fileExt), originalImg.rawformat)
msg = "Uploaded " & fileFld.FileName & " to " & Server.MapPath(upload_dir & upload_original & fileExt)
upload_ok = true
File.Delete(Server.MapPath(upload_dir & upload_original & fileExt))
catch
msg = "Sorry, there was a problem saving your avatar. Please try again."
end try
if not thumb is nothing then
thumb.Dispose()
thumb = nothing
end if
else
msg = "That image does not seem to be a JPG. Upload only JPG images."
end if
catch
msg = "That image does not seem to be a JPG."
end try
end if
if not originalImg is nothing then
originalImg.Dispose()
originalImg = nothing
end if
end if
%><head>
<meta http-equiv="pragma" content="no-cache" />
</head>
<html>
<script type="text/javascript" src="js/jquery-1.3.min.js"></script>
<form enctype="multipart/form-data" method="post" runat="server" id="sendImg">
<input type="file" name="upload_file" id="upload_file" style="-moz-opacity: 0; opacity:0; filter: alpha(opacity=0); margin-top: 5px; float:left; cursor:pointer;" onChange="$('#sendImg').submit();" >
<input type="submit" value="Upload" style="visibility:hidden; display:none;">
</form>
</body>
</html>
Any help would be great! :o)
David
ajax and <input type="file"> don't work well together. the underlying XMLHttpRequest object is restricted and can't actually access the file upload. There is a very limited set of things that you can do with any javascript as it pertains to the file upload. The easiest way to fake what you are trying to do is use an iframe.
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.
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.
below is the coding for 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: </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%> </div><br>
<input name="file" type="file" accept="jpg/jpeg" class="input"> <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>
<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: </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;">BACK TO MAIN ALBUM</div>
<%end if%>
</td>
</tr>
</table>
<%end if%>
<!-- #INCLUDE file="layout_bottom.asp" -->
</body>
</html>
BELOW IS THE CODING FOR 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
%>
CAN ANYONE HELP ME INTEGRATE MULTIPLE UPLOADS IN THE ABOVE MENTIONED FRAMEWORK :) ?
Perhaps a Flash-based upload tool would work better. Many sites that support multiple uploads on a single page are moving to this kind of solution.
Here are a couple that a Google search unearthed:
Multiple File Upload With Progress Bar Using Flash and ASP.NET
MultiPowUpload
FYI, these pages are classic ASP and unrelated to the more recently introduced ASP.NET technology.
I don't know how to fix your problem, but a long, long time ago, I've used the commercially available SoftArtisans FileUp component to allow reliable multi-file uploads in classic ASP.
Did you try using multiple <input type="file"> 's?
EDIT:
What you might try also then, is dynamically creating an IFRAME with the file input field in it and submit that form, holding the file in a temporary location on the server and somehow indicating to the user that they have uploaded one of the files.