• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

How do I get the name of my attachments, into a STRING, so I can save them in the database

I have a form which has a pop up window, called "browse.asp" because here the users choose their attachments which get updated in a FOLDER called "Attachments" on my web server.
That part works.
The problem is that because of my programming when I click Attach Files the original page called "submit.asp" comes up in the pop-up window.  I would like the pop up window to close by itself, but if I do onClick = "window.close()" from the submit button called "ATTACH FILES" then my files do not get saved in the "Attachments" folder... That's why I created another button called "CLOSE WINDOW"

But this doesn't look very good, having the submit.asp page appear in the little pop up window.  Can you help me with that?

Secondly, I also need the name of the files being attached to be saved in a string or array, so that I can display them on the SUBMIT.ASP page, and when I click SUBMIT to save them in the database(that part works)

************Here is my code for browse.asp****************
<FORM METHOD="POST"  ACTION="submit.asp" ENCTYPE="multipart/form-data" id = "mainform" name = "mainform">

<table border="0" cellspacing="2" cellpadding="2" align="center" style = "background:#CBCBCC; border-style: inset">
  <tr>
    <td>      
      <font face="Arial" size="2">Use the "Browse" button to find the files you would like to attach.<BR><br><br>
      </font>
                    <INPUT TYPE="FILE" NAME="attach1" VALUE="" size = "40">
                <INPUT TYPE="HIDDEN" NAME="doc1">
                  <br><br>
                  <INPUT TYPE="submit" value="Attach File" name = "fileBtn" id = "fileBtn" onClick = "window.close()" >
                  <input type = "button" value = "Close Window" name = "close" onClick = "closeWin()" >
<%response.write(doc1) %><br>
      </td>
  </tr>
</table>
<script type="text/javascript">
<!--
document.mainform.doc1.value += document.mainform.attach1.value;

function closeWin() {
      window.close()
}
//-->
</script>



************Here is my code for submit.asp****************
<%@ Language=VBScript %>
<!-- #include file="freeASPUpload.asp" -->
<FORM METHOD="POST"  ACTION="Proposals.asp" onSubmit="return validate(this)" name = "ProposalsForm" ENCTYPE="multipart/form-data" >
<input type = "button" value = "Attach File" name = "attachBtn" id = "attachBtn" onClick = "browseWindow();"  style = "background:#0D6B9C; font-weight:bold; color:#FFFFFF;">      
      <br>                        
      <INPUT type="submit" value="Submit" name="submit" style = "background:#0D6B9C; font-weight:bold; color:#FFFFFF;"><br><br><br>      <INPUT TYPE="HIDDEN" NAME="file1">

<script type="text/javascript">
function browseWindow(){
      window.open("browse.asp","NewWindow","menu=no,width=400,height=200")
}
//-->
</script>

<%
'angie H -- the files are uploaded to folder "angie" and saved there before sent as attachments through the email
Set Upload = New FreeASPUpload
Attachment = Upload.Form("attach1")
Upload.Save("\\opic-intranetdv\wwwroot$\angie\Attachments\")
                  
'Get the Full Path
dim FilePath1
FilePath1 = Upload.Form("doc1")
response.write FilePath1
response.write("<br>")

'Transform the FULL PATH into the FILE NAME only
Set fs=Server.CreateObject("Scripting.FileSystemObject")
      
'fileName1 = rs("ProposalId") & "_" & fs.GetFileName(FilePath1)
fileName1 = fs.GetFileName(FilePath1)
response.write fileName1
response.write("<br>")

set fs=nothing
%>
</FORM>


The last form is proposals.asp, and that puts the form data into the database.  I need the file names of the attachments in the database so that's part of the reason I need them saved in a string or array....
0
Gemini532
Asked:
Gemini532
  • 11
  • 9
1 Solution
 
alorentzCommented:
browse.asp should pst ack to itself, not back to submit.asp.  The file upload code should be in browse.asp, not submit.asp.

And then use the buttons "Save and Close"  and "Save and Attach Another"...as we discussed.  Two options to submit...one just saves and closes the form, and the other saves and allows for additional upload.
0
 
alorentzCommented:
And, for proposals.asp, you would just save the filenames in a session variable, each time you upload a new file.
0
 
alorentzCommented:
Or, I guess you could post the form to the parent, and let submit.asp do the upload: target

<FORM METHOD="POST"  target="_parent" ACTION="Proposals.asp" onSubmit="return validate(this)" name = "ProposalsForm" ENCTYPE="multipart/form-data" >
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Gemini532Author Commented:
My "Save and Close"  button does NOT work.  The "Save and Attach Another" button works....
I think the problem might be the window.close(), it might be closing before saving the file...

<INPUT TYPE="submit" value="Save and Close" name = "closeBtn" id = "closeBtn" onClick = "closeWin()">

<input type = "submit" value = "Save and Attach Another" name = "attachBtn"  id = "attachBtn" >

<script type="text/javascript">
<!--
function closeWin() {
      window.close()
}
//-->
</script>
0
 
Gemini532Author Commented:
Should I use window.opener to get the value session variable which will hold the FileNames...
0
 
alorentzCommented:
<INPUT TYPE="submit" value="Save and Close" name = "closeBtn" id = "closeBtn" onClick = "closeWin()">
<input type = "submit" value = "Save and Attach Another" name = "attachBtn"  id = "attachBtn" >

<%
if request("closeBtn") <> "" then
%>
<script type="text/javascript">
     window.close()
</script>
<%
end if
%>
0
 
alorentzCommented:
Whoops....TAKE OUT THE ONCLICK EVENT IN THE "Save and Close" button...you don't need it.
0
 
Gemini532Author Commented:
How do I create a session variable..
I tried this code, but it doesn't work:

Session("fileName") = Request.Form("attach1")
Response.Write("session " & Session("fileName"))

It's not giving me the value of the URL Session("fileName") is blank when I do Response.Write("session " & Session("fileName")) on browse.asp

Also I had to change
your code:
if request("closeBtn") <> "" then
to
if Upload.Form("closeBtn") <> "" then
Because it was giving me an error
0
 
Gemini532Author Commented:
I figured I save the path in a session variable then get the file name and then add the proposalId to the file name so it will look like this, and then save it in the folder....Becasue otherwise, what if 2 people submit a file with the same name, the original will be overwritten, am I right?

23_Readme.txt
0
 
Gemini532Author Commented:
That was my first idea, but in order to that I've got to get the proposallId from the database in browse.asp, and that's not possible...

Unless I add a unique number to the filename and then I save that unique number in the database as the proposal ID, instead of having the database generate a unique number for each record on its own...

What do you think?
0
 
alorentzCommented:
Probly cuz' you have to use the upload form:

Session("fileName") = Upload.Form("attach1")
0
 
Gemini532Author Commented:
No luck   :(    it still doesn't show anything when I do Response.Write("session " & Session("fileName"))
0
 
alorentzCommented:
Hard to tell what's going or what you've done...been 2 days since you posted.  

So, don't know what code you have, nor your process logic of how the pages are workgin.
0
 
Gemini532Author Commented:
Sorry about that, I had to work on another project.  It was an emergency...

This is my code in browse.asp, the session variable called Session("fileName") is not working      :(

<FORM METHOD="POST"  ACTION="browse.asp" ENCTYPE="multipart/form-data" id = "mainform" name = "mainform">
<table border="0" cellspacing="2" cellpadding="2" align="center" style = "background:#CBCBCC; border-style: inset">
  <tr>
    <td>      
      <font face="Arial" size="2">Use the "Browse" button to find the files you would like to attach.<BR><br><br>
      </font>
                    <INPUT TYPE="FILE" NAME="attach1" VALUE="" size = "80">
                <INPUT TYPE="HIDDEN" NAME="doc1">
                  <br><br>
                  <INPUT TYPE="submit" value="Save and Close" name = "closeBtn" id = "closeBtn">
                  <input type = "submit" value = "Save and Attach Another" name = "attachBtn"  id = "attachBtn" >
                                    
<%response.write(doc1) %><br>
      </td>
  </tr>
</table>
<%
'angie H -- the files are uploaded to folder "angie" and saved there before sent as attachments through the email
Set Upload = New FreeASPUpload
Attachment = Upload.Form("attach1")
Upload.Save("\\opic-intranetdv\wwwroot$\angie\Attachments\")

Session("fileName") = Upload.Form("attach1")
Response.Write("session " & Session("fileName"))
if Upload.Form("closeBtn") <> "" then

%>
<script type="text/javascript">
     window.close()
</script>
<%
end if
%>
</form>


I didn't make changes 2 my other 2 pages....submit.asp and proposals.asp
except that I changed the form in submit.asp from

<FORM METHOD="POST"  ACTION="Proposals.asp" onSubmit="return validate(this)" name = "ProposalsForm" ENCTYPE="multipart/form-data" >
to this
<FORM METHOD="POST"  ACTION="Proposals.asp" onSubmit="return validate(this)" name = "ProposalsForm" >

0
 
alorentzCommented:
What about:


Response.Write("session " & Upload.Form("attach1"))
0
 
Gemini532Author Commented:
But that won't help me when I try to get this data from the submit.asp or the proposals.asp pages...
0
 
Gemini532Author Commented:
I need a session variable to save the data so I can call it from the proposals page and save the name of the files in the database...
0
 
alorentzCommented:
I'm debugging DAMNIT!

I'm not here to go back and forth with you...
0
 
Gemini532Author Commented:
I'm sorry
I did it
Response.Write("session " & Upload.Form("attach1"))
but I got no value!  
0
 
Gemini532Author Commented:
I FIGURED IT OUT!  I saved the file variable into a hidden textbox and then saved the hidden variable into the session variable...
!!!!!!!THANKS!!!!!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 11
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now