forms - How to Insert Record and Upload file using the FreeASPUpload Script -
i want insert record , upload file @ same time, right im using freeaspupload script. when submit form returns error
cannot use generic request collection after calling binaryread
here full source code of page
<% option explicit response.expires = -1 server.scripttimeout = 600 session.codepage = 65001 %> <!-- #include file="uploadclass.asp" --> <% dim uploadsdirvar uploadsdirvar = server.mappath("files_uploaded") function outputform() %> <form name="frmsend" method="post" enctype="multipart/form-data" accept-charset="utf-8" action="form.asp" onsubmit="return onsubmitform();"> <input type="hidden" name="applicationform" value="insert" /> name: <input type="text" name="name_insert" value="" size="30" /> <b>file names:</b><br> file 1: <input name="attach1" type="file" size=35><br> <br> <input style="margin-top:4" type="submit" value="submit"> </form> <% end function function testenvironment() dim fso, filename, testfile, streamtest testenvironment = "" set fso = server.createobject("scripting.filesystemobject") if not fso.folderexists(uploadsdirvar) testenvironment = "<b>folder " & uploadsdirvar & " not exist.</b><br>the value of uploadsdirvar incorrect. open uploadtester.asp in editor , change value of uploadsdirvar pathname of directory write permissions." exit function end if filename = uploadsdirvar & "\test.txt" on error resume next set testfile = fso.createtextfile(filename, true) if err.number<>0 testenvironment = "<b>folder " & uploadsdirvar & " not have write permissions.</b><br>the value of uploadsdirvar incorrect. open uploadtester.asp in editor , change value of uploadsdirvar pathname of directory write permissions." exit function end if err.clear testfile.close fso.deletefile(filename) if err.number<>0 testenvironment = "<b>folder " & uploadsdirvar & " not have delete permissions</b>, although have write permissions.<br>change permissions iusr_<i>computername</i> on folder." exit function end if err.clear set streamtest = server.createobject("adodb.stream") if err.number<>0 testenvironment = "<b>the adodb object <i>stream</i> not available in server.</b><br>check requirements page information upgrading adodb libraries." exit function end if set streamtest = nothing end function function savefiles dim upload, filename, filesize, ks, i, filekey set upload = new freeaspupload upload.save(uploadsdirvar) ' if fails inside script, exception handled if err.number<>0 exit function savefiles = "" ks = upload.uploadedfiles.keys if (ubound(ks) <> -1) savefiles = "<b>files uploaded:</b> " each filekey in upload.uploadedfiles.keys savefiles = savefiles & upload.uploadedfiles(filekey).filename & " (" & upload.uploadedfiles(filekey).length & "b) " next else savefiles = "no file selected upload or file name specified in upload form not correspond valid file in system." end if savefiles = savefiles & "<br>enter number = " & upload.form("enter_a_number") & "<br>" savefiles = savefiles & "checkbox values = " & upload.form("checkbox_values") & "<br>" savefiles = savefiles & "list values = " & upload.form("list_values") & "<br>" savefiles = savefiles & "text area = " & upload.form("t_area") & "<br>" end function %> <html> <head> <title>test free asp upload 2.0</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <style> body {background-color: white;font-family:arial; font-size:12} </style> <script> function onsubmitform() { var formdomobj = document.frmsend; if (formdomobj.attach1.value == "") alert("please press browse button , pick file.") else return true; return false; } </script> </head> <body> <br><br> <div style="border-bottom: #a91905 2px solid;font-size:16">upload files server</div> <% dim diagnostics if request.servervariables("request_method") <> "post" diagnostics = testenvironment() if diagnostics<>"" response.write "<div style=""margin-left:20; margin-top:30; margin-right:30; margin-bottom:30;"">" response.write diagnostics response.write "<p>after correct problem, reload page." response.write "</div>" else response.write "<div style=""margin-left:150"">" outputform() response.write "</div>" end if else response.write "<div style=""margin-left:150"">" outputform() response.write savefiles() response.write "<br><br></div>" end if %> </body> </html> <!-- #include file="adovbs.inc" --> <% '======================================================================================= ' connect database '======================================================================================= dim objconn, objrs set objconn = createobject("adodb.connection") set objrs = createobject("adodb.recordset") objconn.open"provider=microsoft.jet.oledb.4.0;data source="& server.mappath("db/job_database.mdb") &";mode=readwrite|share deny none;persist security info=false" if request("applicationform") = "insert" set inscom=server.createobject("adodb.command") inscom.activeconnection=objconn insname = trim(request("name_insert")) insname = replace(insname,"'","''") inscom.commandtext = "insert applications(aname)values(?)" inscom.parameters.append inscom.createparameter("@name_insert", advarchar, adparaminput, 255, insname) inscom.execute end if %>
i have been searching problem, couldn't make work. although found have use form collection
provided freeaspupload. therefore change
if request("applicationform") = "insert"
to this
if upload.form("applicationform") = "insert"
but returns error, says: variable undefined: 'upload'
if change request method, uploads file not inserts record
if request.querystring("applicationform") = "insert"
what understands insert query in wrong place or so...
please me solve problem.. thanks
i haven't used aspfreeupload i'm guessing bit here.
it appear using request object isn't option you're stuck having use upload.form. code stands, upload object defined , set within context of savefiles function.
try moving database insert code within savefiles function. mean cutting line
dim objconn, objrs
to
inscom.execute
and pasting before 'end function'
you may need move include adovbs.inc directive somewhere before function called. logical place on line below other include directive = uploadclass.asp
Comments
Post a Comment