Hi,
I'm having an issue understanding completely how to handle the file names fields...I have 2 on the form. I want to only allow 2 files for each form...sometimes there may be only 1 attachment.
On my form I have the following:
Here is where the problem is.....Code:<tr> <td>File 1: <input name="attach1" type="file" size=35><br></td> <td>File 2: <input name="attach2" type="file" size=35><br> </td> </tr>
1) If I select 1 file to attach and submit the form, it gets uploaded to the server correctly but its filename gets added to the database fields (file1 & file2) instead of just file1.
2) So I tested to see what happens when I select 2 files to attach, well, it uploads bot the server just fine, but it only inserts the 2nd filename selected in both fields (file1 & file2).
Code:
Thanks for your help!Code:function SaveFiles Dim Upload, fileName, fileSize, ks, i, fileKey Set Upload = New FreeASPUpload Upload.Save(uploadsDirVar) strOriginator = Upload.Form("Originator") strEQNumber = Upload.Form("EquipmentNumber") strPartNo = Upload.Form("PartNo") strEQDesc = Upload.Form("EquipDescription") strFuncLoc = Upload.Form("NCRFuncLoc") strNCRStatus = Upload.Form("NCRStatus") strDispStatement = Upload.Form("Comments") for each fileKey in Upload.UploadedFiles.keys strFile1 = Upload.UploadedFiles(fileKey).FileName strFile2 = Upload.UploadedFiles(fileKey).FileName next if strFile <> "" then set oFSO = Server.CreateObject("Scripting.FileSystemObject") if oFSO.FileExists(uploadsDirVar & "/" & strFile) then oFSO.MoveFile uploadsDirVar & "\" & strFile, Server.MapPath("/Files") & "\" & strFile end if set oFSO = nothing end if Set rs = Server.CreateObject ("ADODB.Recordset") strSQL = "Insert into tblTestNCR (Originator,Equipment,ManPartNo,EQDescription,District,Status,DiscStatement,File1,File2) values ('" & strOriginator & "','" & strEQNumber & "', '" & strPartNo & "', '" & strEQDesc & "', '" & strFuncLoc & "', '" & strNCRStatus & "', '" & strDispStatement & "', '" & strFile1 & "','" & strFile2 & "')" rs.Open strSQL, conn,3,1 Conn.Close Set Conn = Nothing ' If something fails inside the script, but the exception is handled If Err.Number<>0 then Exit function SaveFiles = "" ks = Upload.UploadedFiles.keys if (UBound(ks) <> -1) then SaveFiles = "<B>Files uploaded:</B> " for each fileKey in Upload.UploadedFiles.keys SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) " next else SaveFiles = "The file name specified in the upload form does not correspond to a valid file in the system." end if end function![]()



LinkBack URL
About LinkBacks
it inserts all the other fields on the form and uploads the file to the server but just not inserting the filename(s) to file1 & file2 fields. do you see why the lines in blue would break code to insert the filename? 

Bookmarks