Link to home
Start Free TrialLog in
Avatar of elevatedmarketing
elevatedmarketing

asked on

Image Upload and passing form values for Database Integration

After Fritz has helped me immensely in getting ASPSmartUpload working, my next task is to integrate a back-end user interface that will use ASPSmartUpload to upload 2 image files along with a form with the following information:

Date :  
Location :  
Title :  
Author :  
Body :  
Select a first file :  
Select a second file :  
Contact :  
Email :  

I think the easiest way FOR ME to do this is to create the form and image upload (using ASPSMartUpload) in the form, pass that form to the process page where 1) the Image Upload is processed and 2) the form values and image tags are called up into another form to "confirm" the article.  Then I would pass all of these values into the database.  Is this feasible?  Here's my code for these two pages:

***********FORM CODE*********************

<HTML>
<BODY BGCOLOR="white">

<H1>News Story Upload</H1>
<HR>

<form METHOD="POST" ACTION="/asp/process_news.asp" NAME="PW" ENCTYPE="multipart/form-data">
  <input TYPE="hidden" name="myHidden" value="hidden">
  <table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474">

    <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Date</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Date" value="mm/dd/yyyy" size="12"><br></font></small></td>
          </tr>
            <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Location</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Location" value="" size="40"><br></font></small></td>
                </tr>
                  <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Title</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Title" value="" size="40"><br></font></small></td>
                      </tr>
                        <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Author</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Author" value="" size="40"></font></small></td>
                            </tr>
                              <tr>
      <td width="150"><div align="left"><small><font face="Verdana">Body :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <textarea name="Body" rows="10" value="" cols="40"></textarea><br></font></small></td>
                                  </tr>
    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;first&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td><small><font face="Verdana">
            <input TYPE="file" name="Image1" size="30"></font></small></td>
    </tr>

    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;second&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td><small><font face="Verdana">
            <input TYPE="file" name="Image2" size="30"></font></small></td>
    </tr>

    <tr>
      <td width="150"><div align="left"><p><small><font face="Verdana">Contact :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <SELECT name="Contact" size="1" ><OPTION>Select a Contact</OPTION>
            <OPTION>Cy Emerus</OPTION><OPTION>Skip Joeckel</OPTION>
            <option>Adam Barrington</option>
            </SELECT></font></small></td>
    </tr>

                                  <tr>
      <td><div align="left"><small><font face="Verdana">Email :&nbsp; </font></small></td>
      <td><small><font face="Verdana"><SELECT name="Email" size="1" >
            <option>Select Contact Email</option>
            <OPTION value="mailto:travel@cyemerus.com">travel@cyemerus.com</OPTION>
            <OPTION value="skip@cyemerus.com">skip@cyemerus.com</OPTION>
            <OPTION value="adam@cyemerus.com">adam@cyemerus.com</OPTION></SELECT><br></font></small></td>
                                        </tr>


    <tr>
      <td colspan="2" width="474"><div align="center"><center><p><small><font face="Verdana"><input
      TYPE="Submit"> </font></small></td>
    </tr>
  </table>
</form>

</BODY>
</HTML>


***************Process Page********************

<HTML>
<BODY BGCOLOR="white">

<H1>Story Confirmation</H1>

<%
'Uncomment ONLY after debugging is complete
'on error resume next

Dim mySmartUpload 'declare the component
Dim intCount ' counter for the number of uploaded files
Dim File 'declare the file to upload
Dim filename 'Temp filename
Dim nextPage 'Next Page to forward to

intCount=0 'initialize the counter

'component creation
Set mySmartUpload= Server.CreateObject("aspSmartUpload.SmartUpload")

'limit the file size to 50 Kb, Larger size not recommended
mySmartUpload.MaxFileSize = 250000

' limit the file extensions to pictures files
mySmartUpload.allowedFilesList="gif,jpg"

'Select files on the user computer
mySmartUpload.Upload
' checking all the files
For each file in mySmartUpload.Files
 If not File.IsMissing then
     ' Add a session number to the file name
      fileView = file.FileName
      filename= Server.MapPath(".\") & "\uploads\" & file.FileName
     file.SaveAs(filename)
     intCount = intCount + 1
 End If
Next

' initialize the object
Set mySmartUpload=nothing


%>


  <form METHOD="POST" ACTION="/asp/process_news.asp" NAME="PW" ENCTYPE="multipart/form-data">
  <input TYPE="hidden" name="myHidden" value="hidden">
  <table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474">

    <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Date</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Date" value="<%=Request.Form("Date")%>" size="12"></font></small></td>
          </tr>
            <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Location</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Location" value="<%=Request.Form("Location")%>" size="40"></font></small></td>
                </tr>
                  <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Title</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Title" value="<%=Request.Form("Title")%> " size="40"></font></small></td>
                      </tr>
                        <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Author</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Author" value="<%=Request.Form("Author")%>" size="40"></font></small></td>
                            </tr>
                              <tr>
      <td width="150"><div align="left"><small><font face="Verdana">Body :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <textarea name="Body" rows="10" value="" cols="40"><%=Request.Form("Body")%></textarea></font></small></td>
                                  </tr>
    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;first&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td>
            <input type="text" name="Image1" size="40" value="<%=Request.Form("Image1")%>"></td>
    </tr>

    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;second&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td>
            <input type="text" name="Image2" size="40" value="<%=Request.Form("Image2")%>"></td>
    </tr>

    <tr>
      <td width="150"><div align="left"><p><small><font face="Verdana">Contact :&nbsp; </font></small></td>
      <td width="324">
            <input type="text" name="Contact" size="20" value="<%=Request.Form("Contact")%>"></td>
    </tr>

                                  <tr>
      <td><div align="left"><small><font face="Verdana">Email :&nbsp; </font></small></td>
      <td>
            <input type="text" name="Email" size="20" value="<%=Request.Form("Email")%>"></td>
                                        </tr>


    <tr>
      <td colspan="2" width="474"><div align="center"><center><p><small><font face="Verdana"><input
      TYPE="Submit"> </font></small></td>
    </tr>
  </table>
</form>


</BODY>
</HTML>
 
*************************************

I know that my database connections aren't in there yet.  I'm going to do that after I can call these values correctly into the confirmation form.  Am I doing this right?

Thanks for all the help!
Adam
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

This will be fine. I strongly recommend that you store only the path to the database rather than the image itself.
Also, this will not work:  Request.Form("Body") since your form has this: ENCTYPE="multipart/form-data">

Fritz the Blank
The way to get around that is like this. Instead of:

value="<%=Request.Form("Date")%>"

Try:

value="<%=mySmartUpload.Form("Date")%>"


FtB
Avatar of elevatedmarketing
elevatedmarketing

ASKER

Yes, I only want to store the path (the full path: http://www.elevatedmarketing.com/uploads/news/filename) in the DB.  And I've also found that Request.Form("Body") will not work as well.  Is there a work around?

I guess what I'm what I'm wanting to do is create this interface to where the user completes the entire form on one page, including browsing to upload files, then process the upload and then pass those form values back into a "confirmation" form along with an image view of the files they just uploaded and then they hit "submit" once more to actually insert those values into the DB.  Is this possible?

Adam
Do you want this all on one page or can we break it up?

Please see my last page as a workaround for getting the form values.

FtB
Ok.  This is what I have now.  I'm using the code that we got working yesterday for ASPSmartUpload, but since I'm uploading 2 files, I'm not sure it's working right.

****************Form**************************

<HTML>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>htmlarea test</title>

<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = "";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
  document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
  document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></script>



</head>

<BODY BGCOLOR="white">

<H1>News Story Upload</H1>
<HR>

<form METHOD="POST" ACTION="/asp/process_news_backup.asp" ENCTYPE="multipart/form-data">
  <table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474">

    <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Date</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Date" value="mm/dd/yyyy" size="12"></font></small></td>
          </tr>
            <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Location</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Location" value="" size="40"></font></small></td>
                </tr>
                  <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Title</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Title" value="" size="40"></font></small></td>
                      </tr>
                        <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Author</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Author" value="" size="40"></font></small></td>
                            </tr>
                              <tr>
      <td width="150"><div align="left"><small><font face="Verdana">Body :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <textarea name="Body" rows="10" value="" cols="40"></textarea><br></font></small></td>
                                  </tr>
    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;first&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td><small><font face="Verdana">
            <input TYPE="file" name="Image1" size="30"></font></small></td>
    </tr>

    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;second&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td><small><font face="Verdana">
            <input TYPE="file" name="Image2" size="30"></font></small></td>
    </tr>

    <tr>
      <td width="150"><div align="left"><p><small><font face="Verdana">Contact :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <SELECT name="Contact" size="1" ><OPTION>Select a Contact</OPTION>
            <OPTION>Cy Emerus</OPTION><OPTION>Skip Joeckel</OPTION>
            <option>Adam Barrington</option>
            </SELECT></font></small></td>
    </tr>

                                  <tr>
      <td><div align="left"><small><font face="Verdana">Email :&nbsp; </font></small></td>
      <td><small><font face="Verdana"><SELECT name="Email" size="1" >
            <option>Select Contact Email</option>
            <OPTION value="mailto:travel@cyemerus.com">travel@cyemerus.com</OPTION>
            <OPTION value="skip@cyemerus.com">skip@cyemerus.com</OPTION>
            <OPTION value="adam@cyemerus.com">adam@cyemerus.com</OPTION></SELECT></font></small></td>
                                        </tr>


    <tr>
      <td colspan="2" width="474"><div align="center"><center><p><small><font face="Verdana"><input
      TYPE="Submit"> </font></small></td>
    </tr>
  </table>
</form>
<SCRIPT language="JavaScript1.2">
editor_generate('Body');
</SCRIPT>
</BODY>
</HTML>




********************ASP Process*********************



<HTML>
<BODY BGCOLOR="white">
<%
'Uncomment ONLY after debugging is complete
'on error resume next

Dim mySmartUpload 'declare the component
Dim intCount ' counter for the number of uploaded files
Dim File 'declare the file to upload
Dim filename 'Temp filename
Dim nextPage 'Next Page to forward to

intCount=0 'initialize the counter

'component creation
Set mySmartUpload= Server.CreateObject("aspSmartUpload.SmartUpload")

'limit the file size to 50 Kb, Larger size not recommended
mySmartUpload.MaxFileSize = 250000

' limit the file extensions to pictures files
mySmartUpload.allowedFilesList="gif,jpg"

'Select files on the user computer
mySmartUpload.Upload
' checking all the files
For each file in mySmartUpload.Files
 If not File.IsMissing then
     ' Add a session number to the file name
      fileView = file.FileName
      filename= Server.MapPath(".\") & "\uploads\news\" & file.FileName
     file.SaveAs(filename)
     intCount = intCount + 1
 End If
Next

' initialize the object
Set mySmartUpload=nothing

%>

<H1>Story Confirmation</H1>


  <form METHOD="POST" ACTION="--WEBBOT-SELF--" ENCTYPE="multipart/form-data">
  <!--webbot bot="SaveDatabase" SuggestedExt="asp" S-DataConnection="cydb" S-RecordSource="News" U-Database-URL="cyemerus.mdb" S-Form-Fields="Title Image1 Image2 Email Contact Author Date Body Location" S-Form-DBFields="Title Image1 Image2 Email Contact Author Date Body Location" U-ASP-Include-Url="_fpclass/fpdbform.inc" startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--#include file="_fpclass/fpdbform.inc"--><!--webbot bot="SaveDatabase" i-checksum="40548" endspan -->
  <input TYPE="hidden" name="myHidden" value="hidden">
  <table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474">

    <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Date</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Date" value="<%=mySmartUpload.Form("Date")%>" size="12"></font></small></td>
          </tr>
            <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Location</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Location" value="<%=mySmartUpload.Form("Location")%>" size="40"></font></small></td>
                </tr>
                  <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Title</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Title" value="<%=mySmartUpload.Form("Title")%>" size="40"></font></small></td>
                      </tr>
                        <tr>
      <td width="150"><div align="left">
            <font face="Verdana" style="font-size: smaller">Author</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <input name="Author" value="<%=mySmartUpload.Form("Author")%>" size="40"></font></small></td>
                            </tr>
                              <tr>
      <td width="150"><div align="left"><small><font face="Verdana">Body :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
            <textarea name="Body" rows="10" value="" cols="40"><%=mySmartUpload.Form("Body")%>
</textarea></font></small></td>
                                  </tr>
    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;first&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td>
            <input type="text" name="Image1" size="40" value="<%=mySmartUpload.Form("Image1")%>"></td>
    </tr>

    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;second&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td>
            <input type="text" name="Image2" size="40" value="<%=mySmartUpload.Form("Image2")%>"></td>
    </tr>

    <tr>
      <td width="150"><div align="left"><p><small><font face="Verdana">Contact :&nbsp; </font></small></td>
      <td width="324">
            <input type="text" name="Contact" size="20" value="<%=mySmartUpload.Form("Contact")%>"></td>
    </tr>

                                  <tr>
      <td><div align="left"><small><font face="Verdana">Email :&nbsp; </font></small></td>
      <td>
            <input type="text" name="Email" size="20" value="<%=mySmartUpload.Form("Email")%>"></td>
                                        </tr>


    <tr>
      <td colspan="2" width="474"><div align="center"><center><p><small><font face="Verdana"><input
      TYPE="Submit"> </font></small></td>
    </tr>
  </table>
</form>


</BODY>
</HTML>
 
We can break it up, I was just having a hard time passing those form values from the 1st form to a 2nd upload process page to a final confirmation page. but if you think we should break it up... we can do it.

Here is a bit of reworking on your second page. Please let me know if it works, and then we'll move on to the next step.

FtB
I know there's something wrong with my ASP upload processing code because it's not allowing the passing of form values using:

value="<%=mySmartUpload.Form("Date")%>"

I've plugged all those "<%=mySmartUpload.Form("**")%>" into my confirmation form, but values aren't being passed.
Oh, hang on, let me change this. I just realized that you are using FrontPage?

Yech!!!!

FtB
Did you try using the page that I posted above to see if it worked? It  would be best if we moved incrementally, step by step, so we can isolate where the errors occur.

First--the upload page is still working?
Next--what if you use the page that I had above?

ftB
Hang on! I see the mistake here.

We have to create an instance of the upload object on each page where we are going to do this....

FtB
Sorry about the FP thing!  Old Habits die hard!  The only FP component I want to use is after we upload the files and pass the values into the form, use FP to insert said "confirmation" form into my database.  You probably hate me now! But evangelizing the FrontPagers is a step-by-step process!

First--upload page that we worked on yesterday is not working in this instance i think because I added another file to be uploaded.  (it also may be that it won't work because I've got that confirmation form at the bottom of the same page.

Next--I'm not sure what page above you are referencing.

Okay, let's start over and go step by step. I will be asking for confirmation each step along the way.

Use this as your form:

<HTML>
<BODY BGCOLOR="white">

<H1>News Story Upload</H1>
<HR>

<form METHOD="POST" ACTION="/asp/process_news.asp" NAME="PW" ENCTYPE="multipart/form-data">
  <input TYPE="hidden" name="myHidden" value="hidden">
  <table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474">

    <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Date</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Date" value="mm/dd/yyyy" size="12"><br></font></small></td>
         </tr>
          <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Location</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Location" value="" size="40"><br></font></small></td>
              </tr>
               <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Title</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Title" value="" size="40"><br></font></small></td>
                   </tr>
                    <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Author</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Author" value="" size="40"></font></small></td>
                        </tr>
                         <tr>
      <td width="150"><div align="left"><small><font face="Verdana">Body :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <textarea name="Body" rows="10" value="" cols="40"></textarea><br></font></small></td>
                             </tr>
    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;first&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td><small><font face="Verdana">
          <input TYPE="file" name="Image1" size="30"></font></small></td>
    </tr>

    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;second&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td><small><font face="Verdana">
          <input TYPE="file" name="Image2" size="30"></font></small></td>
    </tr>

    <tr>
      <td width="150"><div align="left"><p><small><font face="Verdana">Contact :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <SELECT name="Contact" size="1" ><OPTION>Select a Contact</OPTION>
          <OPTION>Cy Emerus</OPTION><OPTION>Skip Joeckel</OPTION>
          <option>Adam Barrington</option>
          </SELECT></font></small></td>
    </tr>

                             <tr>
      <td><div align="left"><small><font face="Verdana">Email :&nbsp; </font></small></td>
      <td><small><font face="Verdana"><SELECT name="Email" size="1" >
          <option>Select Contact Email</option>
          <OPTION value="mailto:travel@cyemerus.com">travel@cyemerus.com</OPTION>
          <OPTION value="skip@cyemerus.com">skip@cyemerus.com</OPTION>
          <OPTION value="adam@cyemerus.com">adam@cyemerus.com</OPTION></SELECT><br></font></small></td>
                                  </tr>


    <tr>
      <td colspan="2" width="474"><div align="center"><center><p><small><font face="Verdana"><input
      TYPE="Submit"> </font></small></td>
    </tr>
  </table>
</form>

</BODY>
</HTML>


Then use this as your process_news_backup.asp page:

<HTML>
<BODY BGCOLOR="white">
<%
'Uncomment ONLY after debugging is complete
'on error resume next

Dim mySmartUpload 'declare the component
Dim intCount ' counter for the number of uploaded files
Dim File 'declare the file to upload
Dim filename 'Temp filename
Dim nextPage 'Next Page to forward to

intCount=0 'initialize the counter

'component creation
Set mySmartUpload= Server.CreateObject("aspSmartUpload.SmartUpload")

'limit the file size to 50 Kb, Larger size not recommended
mySmartUpload.MaxFileSize = 250000

' limit the file extensions to pictures files
mySmartUpload.allowedFilesList="gif,jpg"

'Select files on the user computer
mySmartUpload.Upload
' checking all the files
For each file in mySmartUpload.Files
 If not File.IsMissing then
     ' Add a session number to the file name
      fileView = file.FileName
      filename= Server.MapPath(".\") & "\uploads\news\" & file.FileName
     file.SaveAs(filename)
     intCount = intCount + 1
 End If
Next

%>

<H1>Story Confirmation</H1>

  <form METHOD="POST" ACTION=""">
  <input TYPE="hidden" name="myHidden" value="hidden">
  <table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474">

    <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Date</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Date" value="<%=mySmartUpload.Form("Date")%>" size="12"></font></small></td>
         </tr>
          <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Location</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Location" value="<%=mySmartUpload.Form("Location")%>" size="40"></font></small></td>
              </tr>
               <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Title</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Title" value="<%=mySmartUpload.Form("Title")%>" size="40"></font></small></td>
                   </tr>
                    <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Author</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Author" value="<%=mySmartUpload.Form("Author")%>" size="40"></font></small></td>
                        </tr>
                         <tr>
      <td width="150"><div align="left"><small><font face="Verdana">Body :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <textarea name="Body" rows="10" value="" cols="40"><%=mySmartUpload.Form("Body")%>
</textarea></font></small></td>
                             </tr>
    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;first&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td>
          <input type="text" name="Image1" size="40" value="<%=mySmartUpload.Form("Image1")%>"></td>
    </tr>

    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;second&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td>
          <input type="text" name="Image2" size="40" value="<%=mySmartUpload.Form("Image2")%>"></td>
    </tr>

    <tr>
      <td width="150"><div align="left"><p><small><font face="Verdana">Contact :&nbsp; </font></small></td>
      <td width="324">
          <input type="text" name="Contact" size="20" value="<%=mySmartUpload.Form("Contact")%>"></td>
    </tr>

                             <tr>
      <td><div align="left"><small><font face="Verdana">Email :&nbsp; </font></small></td>
      <td>
          <input type="text" name="Email" size="20" value="<%=mySmartUpload.Form("Email")%>"></td>
                                  </tr>


    <tr>
      <td colspan="2" width="474"><div align="center"><center><p><small><font face="Verdana"><input
      TYPE="Submit"> </font></small></td>
    </tr>
  </table>
</form>

<%

' initialize the object
Set mySmartUpload=nothing
%>
</BODY>
</HTML>
So here are my questions:

1) were you able to upload the image?
2) was the form populated?

FtB
Brilliant...  The Upload worked.  Files are in the appropriate folder.

However, this is the display of the confirmation page.

Story Confirmation
 Date :    
Request object error 'ASP 0207 : 80004005'

Cannot use Request.Form

/asp/process_news.asp, line 55

Cannot use Request.Form collection after calling BinaryRead.
 
I see the problem, let me change request.form to the value="<%=mySmartUpload.Form("Date")%>"... hang on.
Sorry for the error! How did I miss that?

FtB
Are you sure that you used the second page that I posted? There is no request.form on it. The page should be:

<HTML>
<BODY BGCOLOR="white">
<%
'Uncomment ONLY after debugging is complete
'on error resume next

Dim mySmartUpload 'declare the component
Dim intCount ' counter for the number of uploaded files
Dim File 'declare the file to upload
Dim filename 'Temp filename
Dim nextPage 'Next Page to forward to

intCount=0 'initialize the counter

'component creation
Set mySmartUpload= Server.CreateObject("aspSmartUpload.SmartUpload")

'limit the file size to 50 Kb, Larger size not recommended
mySmartUpload.MaxFileSize = 250000

' limit the file extensions to pictures files
mySmartUpload.allowedFilesList="gif,jpg"

'Select files on the user computer
mySmartUpload.Upload
' checking all the files
For each file in mySmartUpload.Files
 If not File.IsMissing then
     ' Add a session number to the file name
      fileView = file.FileName
      filename= Server.MapPath(".\") & "\uploads\news\" & file.FileName
     file.SaveAs(filename)
     intCount = intCount + 1
 End If
Next

%>

<H1>Story Confirmation</H1>

  <form METHOD="POST" ACTION=""">
  <input TYPE="hidden" name="myHidden" value="hidden">
  <table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474">

    <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Date</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Date" value="<%=mySmartUpload.Form("Date")%>" size="12"></font></small></td>
         </tr>
          <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Location</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Location" value="<%=mySmartUpload.Form("Location")%>" size="40"></font></small></td>
              </tr>
               <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Title</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Title" value="<%=mySmartUpload.Form("Title")%>" size="40"></font></small></td>
                   </tr>
                    <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Author</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Author" value="<%=mySmartUpload.Form("Author")%>" size="40"></font></small></td>
                        </tr>
                         <tr>
      <td width="150"><div align="left"><small><font face="Verdana">Body :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <textarea name="Body" rows="10" value="" cols="40"><%=mySmartUpload.Form("Body")%>
</textarea></font></small></td>
                             </tr>
    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;first&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td>
          <input type="text" name="Image1" size="40" value="<%=mySmartUpload.Form("Image1")%>"></td>
    </tr>

    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;second&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td>
          <input type="text" name="Image2" size="40" value="<%=mySmartUpload.Form("Image2")%>"></td>
    </tr>

    <tr>
      <td width="150"><div align="left"><p><small><font face="Verdana">Contact :&nbsp; </font></small></td>
      <td width="324">
          <input type="text" name="Contact" size="20" value="<%=mySmartUpload.Form("Contact")%>"></td>
    </tr>

                             <tr>
      <td><div align="left"><small><font face="Verdana">Email :&nbsp; </font></small></td>
      <td>
          <input type="text" name="Email" size="20" value="<%=mySmartUpload.Form("Email")%>"></td>
                                  </tr>


    <tr>
      <td colspan="2" width="474"><div align="center"><center><p><small><font face="Verdana"><input
      TYPE="Submit"> </font></small></td>
    </tr>
  </table>
</form>

<%

' initialize the object
Set mySmartUpload=nothing
%>
</BODY>
</HTML>
wait a second...  It already has the <%=mySmartUpload.Form("formvaluehere")%> in each of the confirmation form fields.

Please make sure that you were pointing to the second page that I posted. You may need to clear your cache and refresh you page a few times.

FtB
I promise you that I just used your code for the second page.  It did upload the file, however it posted the following error in the confirmation table beside the date field:

Request object error 'ASP 0207 : 80004005'

Cannot use Request.Form

/asp/process_news.asp, line 55

Cannot use Request.Form collection after calling BinaryRead.
ok.  I'll try that.
Alright, I cleared the cache and reloaded several times.  Same thing.

I deleted process_news_backup.asp off the server and reposted it.

Still I get the same error.

THe good news is that the upload is still working!
Also, please make sure that you are pointing to the correct second page from your first.

FtB
Okay, let's do this to make sure. On your first page, set the action to this:

<form METHOD="POST" ACTION="/asp/process_fritz.asp" NAME="PW" ENCTYPE="multipart/form-data">

Next, take my last post for the process page and save it as process_fritz.asp

Then let's see what happens.

FtB
That worked beautifully!  The file is uploaded. Almost all the forms are correctly populated.

Except for the image upload forms.  They're just blank.

I had expected that! The file input does not return a value I don't think. We are going to have to grab the names of the images and either repopulate the fields or display the images themselves. Which way would you prefer to go here?

FtB

I'd be fine to display the images themselves on this confirmation form.  However, I also need a path value to input into the database.  What do you think?
I am guessing that we will probably use one and the same....

Let's try this now:

<HTML>
<BODY BGCOLOR="white">
<%
'Uncomment ONLY after debugging is complete
'on error resume next

Dim mySmartUpload 'declare the component
Dim intCount ' counter for the number of uploaded files
Dim File 'declare the file to upload
Dim filename 'Temp filename
Dim nextPage 'Next Page to forward to

intCount=0 'initialize the counter

'component creation
Set mySmartUpload= Server.CreateObject("aspSmartUpload.SmartUpload")

'limit the file size to 250 Kb, Larger size not recommended
mySmartUpload.MaxFileSize = 250000

' limit the file extensions to pictures files
mySmartUpload.allowedFilesList="gif,jpg"

'Select files on the user computer
mySmartUpload.Upload
' checking all the files
dim arrImages(2)
For each file in mySmartUpload.Files
 If not File.IsMissing then
     ' Add a session number to the file name
      fileView = file.FileName
      filename= Server.MapPath(".\") & "\uploads\news\" & file.FileName
     arrImages(intCount) = filename
       file.SaveAs(filename)
     intCount = intCount + 1
 End If
Next

%>

<H1>Story Confirmation</H1>

  <form METHOD="POST" ACTION=""">
  <input TYPE="hidden" name="myHidden" value="hidden">
  <table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474">

    <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Date</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Date" value="<%=mySmartUpload.Form("Date")%>" size="12"></font></small></td>
         </tr>
          <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Location</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Location" value="<%=mySmartUpload.Form("Location")%>" size="40"></font></small></td>
              </tr>
               <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Title</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Title" value="<%=mySmartUpload.Form("Title")%>" size="40"></font></small></td>
                   </tr>
                    <tr>
      <td width="150"><div align="left">
          <font face="Verdana" style="font-size: smaller">Author</font><small><font face="Verdana"> :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <input name="Author" value="<%=mySmartUpload.Form("Author")%>" size="40"></font></small></td>
                        </tr>
                         <tr>
      <td width="150"><div align="left"><small><font face="Verdana">Body :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana">
          <textarea name="Body" rows="10" value="" cols="40"><%=mySmartUpload.Form("Body")%>
</textarea></font></small></td>
                             </tr>
    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;first&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td>
          <input type="text" name="Image1" size="40" value="<%=arrImages(0)%>"></td>
    </tr>

    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;second&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td>
          <input type="text" name="Image2" size="40" value="<%=arrImages(1)%>"></td>
    </tr>

    <tr>
      <td width="150"><div align="left"><p><small><font face="Verdana">Contact :&nbsp; </font></small></td>
      <td width="324">
          <input type="text" name="Contact" size="20" value="<%=mySmartUpload.Form("Contact")%>"></td>
    </tr>

                             <tr>
      <td><div align="left"><small><font face="Verdana">Email :&nbsp; </font></small></td>
      <td>
          <input type="text" name="Email" size="20" value="<%=mySmartUpload.Form("Email")%>"></td>
                                  </tr>


    <tr>
      <td colspan="2" width="474"><div align="center"><center><p><small><font face="Verdana"><input
      TYPE="Submit"> </font></small></td>
    </tr>
  </table>
</form>

<%

' initialize the object
Set mySmartUpload=nothing
%>
</BODY>
</HTML>


FtB
OK.  Almost there.  It populated the Image Fields with this:

Select a first file :    C:\Accounts\elevated\wwwRoot\asp\uploads\news\couple.jpg
Select a second file :    C:\Accounts\elevated\wwwRoot\asp\uploads\news\couple laughing.jpg

Will that be a valid path for me to input into the DB to later recall that image?
It all depends what you want to do with it!!!!

If you would prefer something different, you could store only part of the path like this:

For each file in mySmartUpload.Files
 If not File.IsMissing then
     ' Add a session number to the file name
      arrImages(intCount) = "\uploads\news\" & filename
      fileView = file.FileName
      filename= Server.MapPath(".\") & "\uploads\news\" & file.FileName
      file.SaveAs(filename)
     intCount = intCount + 1
 End If

FtB
I could use just the \uploads\news\filename when I call the images and just fill in the rest of the tag line.

Is it possible to actually display the image from here as well?
I'd actually prefer to store the entire http:// tag and just call it as the image source.
After using that last code, this is what it displays in the confirmation form:

Select a first file :    \uploads\news\
Select a second file :    
\uploads\news\C:\Accounts\elevated\wwwRoot\asp\uploads\news\praying.jpg

Well, you may want to create a test page and play with this. Having the fully qualified path may be the easiest thing, so try this:

For each file in mySmartUpload.Files
 If not File.IsMissing then
     ' Add a session number to the file name
      arrImages(intCount) = "http://www.ElevatedMarketing.com\uploads\news\" & filename
      fileView = file.FileName
      filename= Server.MapPath(".\") & "\uploads\news\" & file.FileName
      file.SaveAs(filename)
     intCount = intCount + 1
 End If

To display your image, then, you would do something like:

<img src="<%=arrImages(0)%>">
<img src="<%=arrImages(1)%>">

FtB
Ok, this is what we're returning now:

Select a first file :     http://www.ElevatedMarketing.com\asp\uploads\news\
Select a second file :  http://www.ElevatedMarketing.com\asp\uploads\news\C:\Accounts\elevated\wwwRoot\asp\uploads\news\woman praying.jpg

I've copied your code exactly.  I've also done the img src as well and they return red x's.  Properties state the URL as the above tags.  
I'm learning... I found the problem!  it was the filename in the array should have been file.FileName instead of just filename!

I can't beleive I fixed something on my own!
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Two last questions:

1.  Is there anyway to make the confirmation field that is calling that image tags UNEDITABLE so that the user can see what's there but not change it?  He wouldn't ever need to change it since it points directly to the image that's already been uploaded.
1.  As I'm new to EE, to which post above should I accept as the answer?
For your first question, try this:

<input type="text" name="Image2" size="40" value="<%=arrImages(1)%>" readonly=true onFocus="Blur()">


As for the second, let's go with ID: 12044632

FtB
That works!  You are a brilliant, brilliant man!
Glad to have helped!

FtB
I don't see where that ID number is listed: 12044632

Comment from fritz_the_blank
Date: 09/13/2004 11:00AM EDT
ID: 12044632


It is the last long post that I made. That is probably the best one to select as it is the most complete.

FtB
Fritz--You've saved my butt.  I should be able to create the other user interfaces I need to from here on out.  However, I may be posting if I get stuck.  The other interfaces I need to do are very similar to this one--two images with an article.  I will need to do one where the user uploads his radio show on WMA with a small description article, but that should be a piece of cake compared to this one.

Is there a size limit to the files that can be uploaded with ASPSmartUpload?  I know I can adjust the size limit, but is there an inherent limit?  (If that needs to be another thread, I'll be glad to do that.  I'm not sure how this whole "new thread/old thread" thing works.
I am glad that I could lend a hand.

As far as new / existing thread stuff goes, try to imagine that you are seaching for a solution using the search engine: it is easiest if each thread concerns a specific issue.

In this case, we have a thread for passing values from one form to another when using an upload component. Posting this to the database might be best as a separate thread.

As far as the size of the file goes, if you go much beyond 1 meg you may start running into issues. The code that we have above limits the size to 250 k for each image. Please let me know if we need to modify this.


Do you need help posting these values to a database or are you set with that?

FtB
I may need some help with DB.  I think I could do it via FP, but I'm learning to that i need to stay away from FP as much as possible.  I'll post here to notify you of a new thread for DB if need be.
Okay, I'll get working on a solution for you as I won't be around tomorrow. What is the name of your database, and what directory is it in? I take it that it is an Access database named cyemerus.mdb?

FtB
It is an Access DB called cyemerus.mdb.

Table: news

It is in directory wwwroot/asp
Okay, if you feel like posting the question now, I can give you some code to work with.

FtB