我们正尝试使用persits上传代码将图片上传到2个不同的文件夹。它只在上传到一个文件夹而不是2个文件夹时有效。
基本上,我们有两个文件夹,一个名为img,另一个是img的子目录,名为small。
我们抓取1张图片并将相同的图片上传到img和小文件夹中。
到目前为止,图片上传到小文件夹但不上传到img文件夹。
下面是相关代码,后面是我从中获取示例代码的链接。
'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
%>
以下是persits链接:
http://www.aspupload.com/manual_memory.html
请不要注意插入代码;它工作正常。
提前致谢
答案 0 :(得分:1)
我看到的一些事情:
两个复制命令都使用file1 他们也没有指定名称,只指定扩展名。 为什么不使用saveas方法? 注释'on next resume next'并在if / then中包装文件夹创建代码并检查文件夹是否存在。然后你可以看到你的错误
答案 1 :(得分:1)
您确定对这两个文件夹具有相同的写入权限吗?另外,你注意到你的文件夹是不同的。如果您确实正确设置了权限,我看到的另一个问题是您的文件夹。你有/ img和img / small那些可能是两个不同的img文件夹。
Upload.CreateDirectory Server.MapPath(&#34; / img&#34;),True Upload.CreateDirectory Server.MapPath(&#34; img / small&#34;),True
我看到的下一个潜在问题在下面的代码中。就在&#39;将文件2复制到File1.copy的小文件夹中。不应该是File2.Copy。
'# 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