This topic is locked
[SOLVED]

 Create an upload page

10/15/2004 10:28:44 AM
ASPRunnerPro General questions
author

I would like to create a table which stores an image (jpg or tiff) or document (txt or pdf). Can ASPRunner generate a page which allows visitors to upload their file?
I'd like to be able to specify where the files get stored on the server. I don't want to store them in the database directly. The database field should contain the filename and that's it.

Admin 10/15/2004

Dan,
this pretty easy to implement. You will need to modify uploader.asp file for this purpose. Here is the code section that you need to modify:

if Request.TotalBytes>0 then

' Instantiate Upload Class

Set objUpload = New clsUpload
' Grab the file name

strFileName = objUpload.Fields("File1").FileName
Set objConn = Server.CreateObject("ADODB.Connection")

Set objRs = Server.CreateObject("ADODB.Recordset")
objConn.Open strConnection
objRs.Open "SELECT " & strPK & ", " & AddWrappers(strField) & " FROM " & AddWrappers(strTable) & " WHERE " & sWhere, objConn, adOpenKeyset, adLockOptimistic

objRs.Fields(strField).AppendChunk objUpload("File1").BLOB & ChrB(0)
objRs.Update

objRs.Close
Set objRs = Nothing

Set objConn = Nothing

Set objUpload = Nothing

Response.Write "File has been saved in database<BR><BR>"

end if


Here is how you need to modify it:

if Request.TotalBytes>0 then

' Instantiate Upload Class

Set objUpload = New clsUpload
' Grab the file name

strFileName = objUpload.Fields("File1").FileName
objUpload("File1").SaveAs(Server.MapPath("/Uploads/") & "\" & objUpload("File1").FileName)
Set objUpload = Nothing

Response.Write "File has been saved<BR><BR>"

end if


Just make sure you have changed upload directory name and assigned write permissions to this directory.

501100 10/19/2004

Sergey,
I'm not sure what I'm doing wrong, however the code that you posted doesn't seem to work. it is giving me an error in the SaveAs routine...
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=2679&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' /> Error Type:

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=2679&image=2&table=forumreplies' class='bbc_emoticon' alt=':(' /> ADODB.Stream (0x800A0BBC)

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=2679&image=3&table=forumreplies' class='bbc_emoticon' alt=':(' /> Write to file failed.

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=2679&image=4&table=forumreplies' class='bbc_emoticon' alt=':(' /> /edcs/asprunner/imagetest/include/clsField.asp, line 178
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=2679&image=5&table=forumreplies' class='bbc_emoticon' alt=':ph34r:' /> line 176 ' Save the binary data to file system

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=2679&image=6&table=forumreplies' class='bbc_emoticon' alt=':ph34r:' /> line 177 ' Overwrites file if previously exists!

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=2679&image=7&table=forumreplies' class='bbc_emoticon' alt=':ph34r:' /> line 178 Call lobjStream.SaveToFile(pstrFileName, adSaveCreateOverWrite)
My code is slightly different so I've listed it below...

Dim objUpload

Dim strFileName

Dim strServerFileName

Dim objConn

Dim objRs

Dim lngFileID
strTable = Request.QueryString("pictable")

strField = Request.QueryString("picfield")

sWhere = Request.QueryString("where")

strPK = Request.QueryString("PK")

strBack = Request.QueryString("Back")

If strBack="" Then

strBack=1

Else

strBack = CStr(CLng(strBack)+1)

End If
If Request.TotalBytes>0 Then
' Instantiate Upload Class

Set objUpload = New clsUpload
' Grab the file name

strFileName = objUpload.Fields("File1").FileName



strServerFileName = Server.MapPath("/Uploads/") & "\" & objUpload("File1").FileName



response.write(strServerFileName)

'response.end
      objUpload("File1").SaveAs(strServerFileName)
Set objConn = Server.CreateObject("ADODB.Connection")

Set objRs = Server.CreateObject("ADODB.Recordset")
objConn.Open strConnection
objRs.Open "SELECT " & strPK & ", " & AddWrappers(strField) & " FROM " & AddWrappers(strTable) & " WHERE " & sWhere, objConn, adOpenKeyset, adLockOptimistic

objRs.Fields(strField) = strServerFileName
objRs.Update

objRs.Close
Set objRs = Nothing

Set objConn = Nothing

Set objUpload = Nothing

Response.Write "File has been saved in database<BR><BR>"

End If

Admin 10/19/2004

Dan,
you need to make sure:

  1. Upload directory name is correct
  2. Everyone has write permissions on this directory

501101 10/20/2004

Sergey,
I should have mentioned in my last post that I had set the permissions to allow read/write access to the directory. However I did disable script running because there shoudl never be a script in this directory that needs to be executed. This directory should only contain uploaded documents.
Thanks,

Dan

P
primusvarun 9/18/2007

HI, This is varun

Replace
strFileName = objUpload.Fields("File1").FileName
to
strFileName = objUpload.Fields("File1").FilePath
u will get ur answer

Dan,

this pretty easy to implement. You will need to modify uploader.asp file for this purpose. Here is the code section that you need to modify:
Here is how you need to modify it:
Just make sure you have changed upload directory name and assigned write permissions to this directory.