Link to home
Start Free TrialLog in
Avatar of bjv211
bjv211

asked on

Uploading files

I want to be able to upload files to a directory that will be selected by the user in the first page:

<form action="upload.cfm" method="post">
<select name="site" size="1">
    <cfoutput query="getoptions">
      <option value="#tblName#">#description#</option>
      </cfoutput>
  </select>
 <input type="submit" value="Go"></form>

then the upload page:

<cfif IsDefined("Form.Submit")>
<cflock name="FileToUpload" type="exclusive" timeout="10">
     <cffile
          destination="media/#form.site#"
          action="upload"
          nameconflict="makeunique"
          filefield="FileToUpload">
</cflock>
<cfelse>
     <form method="post" action="done.html" enctype="multipart/form-data">
          <input type="file" name="FileToUpload">
          <br>
          <input type="submit" name="submit" value="Upload">
     </form>
</cfif>

but i keep gettting the error SITE undefined in FORM ??
ASKER CERTIFIED SOLUTION
Avatar of Tacobell777
Tacobell777

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
Avatar of Tacobell777
Tacobell777

I *believe* you are posting to the action page and display a form, then submit that form and expect the form field from the first submit to be present, correct?
If so, you would need to include it as a hidden variable, form fields are not automatically passed from form to form.
Avatar of bjv211

ASKER

i'm passing form value from selection page to action page... on the action page it would be nice if it could post to itself and add the file name to my central database...is this possible or do i need to post to a secondary page
did you try my code?
Avatar of bjv211

ASKER

yea but i cant figure out where the file is going
yes its possible, try my code and it should work...
Avatar of bjv211

ASKER

i'm going to have to get some sleep and come back with a fresh mind.... i'll tty tomorrow
> yea but i cant figure out where the file is going

thats a different question isn't it?
media/#form.site# is where the file is going, however this should really be a full path like c:\temp\whatever
SOLUTION
Avatar of Renante Entera
Renante Entera
Flag of Philippines 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
Oooopppssss!  Forgot something on the part of the value of hidden field "site".

Instead of : value="#form.site#"

Replace it with this : value="<cfoutput>#form.site#</cfoutput>"


Regards!
eNTRANCE2002 :-)
Avatar of bjv211

ASKER

ok, after tweaks with you code, i got it uploading..thanks for the direction.  Now, I would like to get the name of the file that was uploaded, copy this to my database for indexing.

I have tables that correspond to the folders in media  FOr example I have NCtrip as a table and in it I have fields "description", filename.  I would like the table to be updated with the new file.  I know how to do the query, i just don't know how to get the filename I just uploaded.

Avatar of bjv211

ASKER

I just had a thought...can i just pass the variable "filetoupload to the next page and use this to process thequery?  i'll try
Avatar of bjv211

ASKER

ok so here is what I need help on.  I need to update my access table with the recently uploaded filename.  I realize you can do this using ServerFile attribute but I can't figure out where to place this code. here is my code that uploads the file.

first page:
<cfquery name="getoptions" datasource="pics">
SELECT * FROM cat ORDER BY description ASC
</cfquery>
<body>
<p class="pagehead" align="center">Upload Destination</p>
<div align="center">
<form action="upload.cfm" method="post">
  <select name="folder" size="1">
    <cfoutput query="getoptions">
      <option value="#tblName#">#description#</option>
    </cfoutput>
  </select>
  <input type="submit" value="Go">
</form>

2nd page:
<cfif IsDefined("Form.Submit")>

  <cfset FullPath = 'D:\inetpub\trappedinnyc\logged_in\media\#form.folder#'>
  <!--- Uploading the file to the directory --->
  <cffile destination="#FullPath#" action="upload" nameconflict="makeunique" filefield="FileToUpload">
<cfelse>
  <form method="post" action="" enctype="multipart/form-data">
    <input type="hidden" name="folder" value="<cfoutput>#form.folder#</cfoutput>">
    <input type="file" name="FileToUpload"><br>
      <input type="submit" name="submit" value="Upload">
  </form>
</cfif>
Hi bjv211!

I think this deserves to be another question since you're main question is this :
  "I want to be able to upload files to a directory that will be selected by the user in the first page"

And it has been answered already.  Am i right ???

By the way, just a reminder.  If you want to get the root directory of your templates do not do it in a hard-coded way.

Use this : <cfset FullPath = '#GetDirectoryFromPath(GetBaseTemplatePath())#media\#form.folder#'>

Hope this makes sense ...


Regards!
eNTRANCE2002 :-)

Avatar of bjv211

ASKER

well since we never really answered my question  "I want to be able to upload files to a directory that will be selected by the user in the first page"
i will award by default.
Hi bjv211!

I think I have answered your question.  Haven't you tried my code ???

>> I want to be able to upload files to a directory that will be selected by the user in the first page <<
     The lines below answered it :

     <cfset CurrentPath = GetDirectoryFromPath(GetBaseTemplatePath())>
     <cfset FullPath = '#CurrentPath#media\#form.site#'>
     <!--- Creating a new directory within your folder "media" --->
     <cfdirectory action="create" directory="#FullPath#">
     <!--- Uploading the file to the newly-created directory --->
     <cffile destination="#FullPath#" action="upload" nameconflict="makeunique" filefield="FileToUpload">

And I know that Tacobell777 will agree with me.  Am I right Tacobell777 ?


Regards!
eNTRANCE2002 :-)