4

我正在尝试以经典的 asp 上传图像,并使用下面的代码。

file_path  = "/uploads/events/upload_img"
img_folder = Server.MapPath(file_path)

Set Upload = Server.CreateObject("Persits.Upload")
Upload.CodePage = 949
Upload.SetMaxSize (500 * 1024), True
Upload.OverwriteFiles = false
Upload.CreateDirectory img_folder, True
Upload.save

Upload.Files("img1")

这里img1包含从用户获取的图像:

<input type="file" name="img1" />

但是它可以正确执行,但在文件夹中看不到图像 /uploads/events/upload_img

谁能告诉我这是为什么?谢谢

4

2 回答 2

1

因为您使用的是save()不带参数的方法,所以文件被上传到服务器的内存,而不是文件夹。

尝试这个:

img_folder = Server.MapPath("/uploads/events/upload_img")

Set Upload = Server.CreateObject("Persits.Upload")
Upload.CodePage = 949
Upload.SetMaxSize (500 * 1024), True
Upload.OverwriteFiles = false
Upload.CreateDirectory img_folder, True
Upload.Save(img_folder)

uploadedImg = Upload.Files("img1")

这是Persits.Upload 对象引用中Save() 方法的链接。

于 2012-04-21T09:57:51.230 回答
0

下面的代码有效。只需从多部分形式发布到它。

=========================
EXAMPLE MULTIPART FORM
=========================

<form method="post" enctype="multipart/form-data" action="">
<input type="file" name="img1" /><input type="submit" />
</form>

=========
ASP CODE
=========

Set Upload = Server.CreateObject("Persits.Upload")
Upload.CodePage = 949              
Upload.SetMaxSize (500 * 1024), True
Upload.OverwriteFiles = False ' Generate unique names
Upload.Save "C:\path\filename.jpg"

Set File = Upload.Files(1)
uploadedImg = File.ExtractFileName

Set Upload = Nothing
Set File = Nothing
于 2012-04-25T16:36:18.497 回答