-1

I need to upload a file using JS,

<input type="file" name="picUpload" id="picUpload" />

 <% set pic = Request.Form("picUpload")
set Amount = Request.Form("tbAmountProduct")
set desc = Request.Form("tbDescProduct")
set price= Request.Form("tbPriceProduct")
set pcId =Request.Form("ddlCategoryForProd")
set pbId =Request.Form("ddlBrandForProd")
set pName=Request.Form("tbProductName")
IF((bName<>"")AND(Amount<>"")AND(desc<>"")AND(price<>"")AND(pcId<>"-1")AND(pbId<>"-1")AND (pic<>"")) THEN


    set con = Server.CreateObject("ADODB.Connection")
    con.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("WebData/DB.mdb") & ";"  
    set rs = con.Execute("Select * FROM Products WHERE ProductName = '"&pName&"' and mode= true")
        IF rs.EOF = true then           
        SET sql ="Insert Into Products (ProductName,SupID,CatID,Amount,Price,Pic,Description) Values( '"&pName&"','"&pbId&"','"&pcId&"','"&Amount&"','"&price&"','"&pic&"','"&desc&"')"
        SET rs =con.Execute(sql)%>

How can I get the file's path and link it to the database and to a specific folder in the project's folder? Thank you very much.

user2922456
  • 391
  • 4
  • 10
  • 24
  • Sorry, I edit the code – user2922456 Mar 27 '14 at 12:02
  • The problem you are going to have is when you're uploading files you have to set your `
    ` to use attribute `enctype="multipart/form-data"` this will send your upload and your form fields as binary. Which means you can't use the `Response.Form` collection to retrieve your values you will have to use a combination of `Request.BinaryRead()` and `Request.TotalBytes` to parse your binary data and exact your file and fields. I've done this many times using the [Free ASP Upload](http://www.freeaspupload.net/) script which is pure `VBScript` without relying on COM components as some solutions do.
    – user692942 Mar 27 '14 at 12:13

1 Answers1

0

I'm not sure where JavaScript comes into this.

As I understand you want a script which upload a file to your server and save the filename to the database. For the upload bit you can install a third party component like Persits ASPUpload, or use the FreeAspUpload script suggested by Lankymart above.

(Alternatively you could look at using asp.net - if your server supports it and you have even rudimentary knowledge of .net. I love Classic ASP but it's not very good for uploading files)

Anyway here's a question I answered last year. It was about doing what I think you are trying to do, but using AspFreeUpload.

How to Insert Record and Upload file using the FreeASPUpload Script

Community
  • 1
  • 1
John
  • 4,658
  • 2
  • 14
  • 23
  • Why's it not good for uploading files @John? Can't say I've ever had a problem, FreeAspUpload has always worked well for me, the problems people hit and then don't know how to solve usually is setting `AspMaxRequestEntityAllowed` in IIS 6 and [How do I enable upload of large files in classic ASP](http://stackoverflow.com/a/22386054/692942) on IIS 7+? – user692942 Mar 27 '14 at 16:05
  • @Lankymart I've found that .net is better if you want to set limitations on the size of the file you're uploading, or check that it's a gif or jpeg (and I don't just mean checking the file extension) – John Mar 27 '14 at 16:31
  • Limits is checking `Request.TotalBytes` against a predefined limit (In my own implementation based off FreeAspUpload I added a Limit property and used that, benefit of this was I could then use `Err.Raise()` to bubble the event out of the class into the ASP page so it could be handled. Content Type is ripped straight out of the binary when the `Request.BinaryRead()` checks the boundaries for the file(s) `oUploadFile.ContentType = Right(auxStr, Len(auxStr)-InStrRev(auxStr, " "))` and makes available in a tidy `ContentType` property of the File in the Upload class `UploadedFiles` collection. – user692942 Mar 27 '14 at 16:38