Asp classic 我想得到这个代码上传图片到2个不同的文件夹

Asp classic 我想得到这个代码上传图片到2个不同的文件夹,asp-classic,Asp Classic,我们正在尝试使用persits上载代码将图片上载到2个不同的文件夹。当只上传到一个文件夹而不是两个文件夹时,它就可以工作 本质上,我们有两个文件夹,一个叫做img,另一个叫做small,是img的子目录 我们抓取一张图片,将同一张图片上传到img和小文件夹中 到目前为止,图片被上传到小文件夹,但没有上传到img文件夹 下面是相关代码,后面是我从中获得示例代码的链接 'Upload.asp <form name="form" action="process.asp" method="post

我们正在尝试使用persits上载代码将图片上载到2个不同的文件夹。当只上传到一个文件夹而不是两个文件夹时,它就可以工作

本质上,我们有两个文件夹,一个叫做img,另一个叫做small,是img的子目录

我们抓取一张图片,将同一张图片上传到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



%>
”Upload.asp
附加IMG文件夹:
小文件夹的附件:

'Process.asp 我看到了几件事:

两个复制命令都使用file1 它们也不指定名称,只指定扩展名。 为什么不使用saveas方法呢?
注释掉“错误时继续下一步”,将文件夹创建代码包装在if/then中,并检查文件夹是否存在。然后您可以看到您的错误

您确定对这两个文件夹具有相同的写入权限吗?另外,你注意到你的文件夹不同了吗。如果您的权限设置正确,我看到的另一个问题是您的文件夹。您有/img和img/small,它们可能是两个不同的img文件夹

Upload.CreateDirectory Server.MapPath(“/img”),True Upload.CreateDirectory Server.MapPath(“img/small”),True

我看到的下一个潜在问题是下面的代码。就在“将文件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

我不会在这里发布数据库字符串/密码。其他数据库操作代码真的相关吗?请只包含相关的代码块,这样我们就不必费力地阅读所有代码了。但是既然您已经发布了它,我可以指出您在SQL注入保护方面的尝试是不够的。学习使用参数化查询,而不是像代码所显示的那样,用“替换”来替换“这很容易出现错误和漏洞”。@Chidi Okeh-为了摆脱Michael所说的,您现在可能应该更改DB PW了。这个网站的用户仍然可以在变更日志中查看它。谢谢你,Michael。你说我没有指定名称,只指定了扩展名。你到底是什么意思?我认为标记中的名称是file1和file2?file1.Copy(Server.MapPath(“/img/”&file1.Ext))file1.Ext只是扩展名。此外,在“出错时继续下一步”之前添加“继续”。这样,它将抛出一个错误。如Padas所说,如果您有权限错误,它会让您知道。小文件夹是img的子目录。Small文件夹位于img文件夹内,已在img上设置权限并设置为Small以继承该权限。