We are trying to use persits upload code to upload pictures to 2 different folders. It works when uploading to just one folder but not 2 folders.
Essentially, we have two folders, one is called img and the other is a subdirectory of img called small.
We grab 1 picture and upload same picture into both img and small folders.
So far, the picture gets uploaded to small folder but not to img folder.
Below is the relevant code followed by a link where I got my sample code from.
'Upload.asp
<form name="form" action="process.asp" method="post" ENCTYPE="multipart/form-data">
<Table>
<tr>
<td class="body1" div align="right">Attach for IMG folder:</div></td>
<td><INPUT NAME="file1" TYPE="FILE" value="" SIZE=30></td>
</tr>
<tr>
<td class="body1" div align="right">Attach for SMALL folder:</div></td>
<td><INPUT NAME="file2" TYPE="FILE" value="" SIZE=30></td>
</tr>
</table>
</td>
</tr>
</table>
<hr color="silver">
<table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td><div align="center">
<input type="image" name="submit" id="submit2" title="submit to db." border="0" src="images/submitbutton.jpg" width="142" height="47" alt="Submit Button">
</div></td>
</tr>
</table>
</form>
'Process.asp
<%
Set Upload = Server.CreateObject("Persits.Upload")
' Limit file size to 5000000 bytes, throw an exception if file is larger
Upload.SetMaxSize 5000000, True
' Save to memory. Path parameter is omitted
Count = Upload.Save
' Two images must be selected
If Count <> 2 Then
Response.Write "You must select 2 jpeg files."
Response.End
End If
' Intercept all exceptions to display user-friendly error
On Error Resume Next
' Create two folders, ignore "already exists" error
Upload.CreateDirectory Server.MapPath("/img"), True
Upload.CreateDirectory Server.MapPath("img/small"), True
' Obtain File objects
Set File1 = Upload.Files("file1")
Set File2 = Upload.Files("file2")
' Build name from session ID
'Name = Session.SessionID
' Save
'File1.SaveAs (Server.MapPath("/img/" & File1.Ext))
'File2.SaveAs (Server.MapPath("/img/small/" & File2.Ext))
' Copy file 1 to img folder
File1.Copy (Server.MapPath("/img/" & File1.Ext))
' Delete from temp folder
File1.Delete
' Copy file 2 to small folder
File1.Copy (Server.MapPath("/small/" & File1.Ext))
' Delete from temp folder
File2.Delete
For Each File in Upload.Files
If File.ImageType <> "JPG" Then
Response.Write "The image type you are uploading is not a JPGE image."
File.Delete
Response.End
End If
Next
Dim objConn,connectstr,objRS,prodset,specialset,bncatset,featureset
connectstr = "Provider=sqloledb; Data Source=scartmil.db.8911524.hostedresource.com; Initial Catalog=scartmil; User ID=999999; Password=8888;"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open connectstr
catdescription = Upload.Form(trim("catdescription"))
pcode = Upload.Form("pcode")
pname = Upload.Form(trim("pname"))
pdescription = Upload.Form(trim("pdescription"))
pPhoto = Upload.Form("pPhoto")
cstock = Upload.Form("cstock")
cprice = Upload.Form("UnitPrice")
'sanitize to avoid sql injection
catdescription = replace(catdescription,"'","''",1,-1,1)
pcode = replace(pcode,"'","''",1,-1,1)
pname = replace(pname,"'","''",1,-1,1)
pdescription = replace(pdescription,"'","''",1,-1,1)
pPhoto = replace(pPhoto,"'","''",1,-1,1)
cstock = replace(cstock,"'","''",1,-1,1)
cprice = replace(cprice,"'","''",1,-1,1)
'response.write cprice
'response.end
sql = "INSERT INTO products (ccategory, " & _
"ccode, " & _
"cname, " & _
"cdescription, " & _
"cimageurl, " & _
"cstock, " & _
"cprice) " & _
"VALUES (" & _
""&catdescription&", " & _
"'"&pcode&"', " & _
"'"&pname&"', " & _
"'"&pdescription&"', " & _
"'"&pPhoto&"', " & _
""&cstock&", " & _
""&cprice&")"
'response.write sql
'response.end
set rs = objConn.Execute(sql)
'ok record in, now retrieve the primary key
sql = "SELECT products.catalogID FROM products ORDER BY products.catalogID DESC"
'response.write sql
'response.end
set prodset = objConn.execute(sql)
if not prodset.EOF then
bCatalog = prodset("CatalogID")
end if
sql= "INSERT INTO bndCategoryProduct (bCategoryId, " & _
"bCatalogId) " & _
"VALUES (" & _
""&catdescription&", " & _
""&bCatalog&")"
'response.write sql
'response.end
set bncatset = objConn.execute(sql)
objConn.Close
Set objConn=Nothing
%>
Here is the persits link:
http://www.aspupload.com/manual_memory.html
Please don’t pay attention to the insert code; it works fine.
Thanks in advance
Are you sure you have the same write permissions to both folders? also, did you notice your folders are different. If you do have the permissions set correctly, the other issue I see is your folders. You have /img and img/small Those could potentially be two different img folders.
Upload.CreateDirectory Server.MapPath(“/img”), True
Upload.CreateDirectory Server.MapPath(“img/small”), True
The next potential problem I see is in the code below. Just under ‘ Copy file 2 to small folder you have File1.copy. Shouldn’t that be File2.Copy.