Aaran
Aaran

Reputation: 41

Uploading Image in Classic ASP and Image not found in the directory

I am trying to upload a image in classic asp and am using below code for the same.

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")

Here img1 contains the image taken from user through:

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

However it executes correctly but image is not seen in the folder /uploads/events/upload_img

Can anyone tell me why this is? Thanks

Upvotes: 4

Views: 6209

Answers (2)

Ryan.B
Ryan.B

Reputation: 40

The code below works. Just post to it from a multipart-form.

=========================
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

Upvotes: 0

Rory McCrossan
Rory McCrossan

Reputation: 337656

Because you are using the save() method with no parameters, the file is being uploaded to the server's memory, not to a folder.

Try this:

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")

Here's a link to the Save() method in the Persits.Upload object reference.

Upvotes: 1

Related Questions