PDA

View Full Version : how i can know the name of the file


bmwmpower
03-26-2003, 02:15 PM
i have code for upload files so what i want is
the name of the file who i uplod it add it in data base


<FORM onSubmit="startupload();" name="theForm" ACTION="SaveFilesresp2.asp" ENCTYPE="MULTIPART/FORM-DATA" METHOD="POST">
<div align="center">File Name...<BR>
<INPUT TYPE="FILE" NAME="myFile" size="30" class=navbutton >
<BR>
<BR>
<input name="I1" type="submit" value="Upload File" class=navbutton >
<br>
<BR>
<font color="#000033"><b><font color="#FFFFFF" size="2">NOTE : Please
be patient, you will&nbsp; receive a Progress Bar notification until
the file is completely transferred..</font></b></font></div>
</FORM></td></tr>


this is the code what i want now is how i can add the name of the file who i uploaded in database ( the name of file only )

Spudhead
03-26-2003, 02:48 PM
The way I often do it is to pass the file path as a hidden field. So in that "startupload()" function you could just have a line that does:

document.theForm.myHiddenField.value=document.myFile.value;

and then it's nice and easy to get out at the other end. What are you using for the file upload? SA_FileUp?

raf
03-26-2003, 02:50 PM
sql = "INSERT INTO table (variable) VALUES('thename')"
sql = replace(sql,"thename",replace(request.form("myFile"),"'","''"))

dim condb
set condb=server.CreateObject("adodb.connection")
condb.Open("provider=microsoft.jet.oledb.4.0;data source="&server.MapPath("database.mdb"))

condb.Execute sql,numberinserted
'comment: numberinserted is a parameter that return the number of records that are inserted

condb.Close
set condb = nothing

if numberinserted=1 then
response.write("Yeah")
else
response.write("Problem. Data was not saved in db. ")
end if



you need to change table and (variable) with your table and variablename.

glenngv
03-27-2003, 03:23 AM
you won't be able to use Request.Form if enctype is multipart/form-data, which is required for file upload. Whatever upload component bmwmpower is using, it should have its own form collection to retrieve form data.

whammy
03-29-2003, 12:53 AM
What Glenn said!

It really helps to read the readme.txt (in the case of ASP/VBScript classes) or whatever documentation comes with the upload component, regarding form values. I just did this for the first time today (!), and had no problem (once I read the instructions). ;)

Which reminds me of something I heard somewhere, long ago... "If all else fails, read the instructions!". :)

bmwmpower
03-29-2003, 01:18 PM
ok i will tell u my uplod code to tell me what i must do

<%
'--- Instantiate the FileUp object
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")

'--- Assign the same progress ID that we assigned to the progress object
oFileUp.ProgressID = CInt(Request.QueryString("progressid"))


'oFileUp.Path = Server.MapPath(Application("vroot") & "/temp")
'oFileUp.Path = Server.MapPath(Application("vroot") & Session("temp"))
oFileUp.Path = Server.MapPath(Application("vroot") & Session("up") )
'server.mappath(".") & "\" & Session("temp")
'...
oFileUp.Form("myFile").Save
'...
Response.Redirect "file_uploads.asp?o=success"
%>



this my upload code so how i can know the name of the file to save it in my db

whammy
03-30-2003, 01:12 PM
The answer is right there in front of you:

Dim myFileName
myFileName = oFileUp.Form("myFile")

If you're using a path, just split it by ("\"), i.e.:

Dim myFileName, patharray

patharray = Split(oFileUp.Form("myFile"),"\")
myFileName = patharray(UBound(patharray))

Haven't tested it, but it should work... :)