View Full Version : Image Upload
holty
03-26-2003, 06:58 PM
Hi,
I would like to upload an image to images/upload and store the filename and extension (for example, 004.jpg) in a field in a table in an Access Database.
Has anyone any code to do this? I looked into it and could only save the images as blobs which I'm not allowed to do!
Any help would be great
ta
alexk13
03-27-2003, 04:57 AM
Check out this site
www.stardeveloper.com (http://www.stardeveloper.com/)
I found scripts there for uploading images (and oher files) to disk an to database. Better than that, the script they have do not use 3rd party components, just pure ASP.:)
holty
03-27-2003, 09:38 AM
Thanks, I found some code to upload, now I have a problem - I have a form with several fields on and a file upload. I can't get the information out of the fields:(
alexk13
03-28-2003, 11:47 PM
Getting the other fields on your form is still pretty easy, but you can't use the request object on the same page when you are uploading a file through the script.
Instead of using the request object, the upload script uses a class that does have options for getting other form fields as well.
If you are using the sample from stardeveloper.com, in the insert.asp file, you should see the following code (near the top of the file): (i've put in line number to help with my explanation that follows)
06 Dim load
07 Set load = new Loader
08
09 ' calling initialize method
10 load.initialize
11
12 ' File binary data
13 Dim fileData
14 fileData = load.getFileData("file")
15 ' File name
16 Dim fileName
17 fileName = LCase(load.getFileName("file"))
18 ' File path
19 Dim filePath
20 filePath = load.getFilePath("file")
21 ' File path complete
22 Dim filePathComplete
23 filePathComplete = load.getFilePathComplete("file")
24 ' File size
25 Dim fileSize
26 fileSize = load.getFileSize("file")
27 ' File size translated
28 Dim fileSizeTranslated
29 fileSizeTranslated = load.getFileSizeTranslated("file")
30 ' Content Type
31 Dim contentType
32 contentType = load.getContentType("file")
33 ' No. of Form elements
34 Dim countElements
35 countElements = load.Count
36 ' Value of text input field "name"
37 Dim nameInput
38 nameInput = load.getValue("name")
39 ' Path where file will be uploaded
40 Dim pathToFile
41 pathToFile = Server.mapPath("uploaded/") & "\" & fileName
42 ' Uploading file data
43 Dim fileUploaded
44 fileUploaded = load.saveToFile ("file", pathToFile)
45
46 ' destroying load object
47 Set load = Nothing
Lines 12 to 32: Get the file an other info about the file
Lines 33 to 35: Counts how many field items are in the form (not too sure why they put this here, I've never used it)
Lines 36 to 38: Gets the value from the form field labelled "name"
Since you should know what fields you have in your form, it should be easy enough to figure out how to get them in this page, but here's an example:
If you have a form field labelled "EmailAddress", you would need the following lines in the above code to retireve this info from the form:
' Value of text input field "EmailAddress"
Dim emailAddressInput
emailAddressInput = load.getValue("EmailAddress")
You can do this for any forms, with any number of fields and file uploads.
Now, all you form field values are stored in variables, so further down the page in you insert.asp, you just need to decide what you are going to do with the values in these variables.
Hope this helps
Alex
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.