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#">#descrip tion#</opt ion>
</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.s ite#"
action="upload"
nameconflict="makeunique"
filefield="FileToUpload">
</cflock>
<cfelse>
<form method="post" action="done.html" enctype="multipart/form-da ta">
<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 ??
<form action="upload.cfm" method="post">
<select name="site" size="1">
<cfoutput query="getoptions">
<option value="#tblName#">#descrip
</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.s
action="upload"
nameconflict="makeunique"
filefield="FileToUpload">
</cflock>
<cfelse>
<form method="post" action="done.html" enctype="multipart/form-da
<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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
ASKER
yea but i cant figure out where the file is going
yes its possible, try my code and it should work...
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.sit e#</cfoutp ut>"
Regards!
eNTRANCE2002 :-)
Instead of : value="#form.site#"
Replace it with this : value="<cfoutput>#form.sit
Regards!
eNTRANCE2002 :-)
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.
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.
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
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#">#descrip tion#</opt ion>
</cfoutput>
</select>
<input type="submit" value="Go">
</form>
2nd page:
<cfif IsDefined("Form.Submit")>
<cfset FullPath = 'D:\inetpub\trappedinnyc\l ogged_in\m edia\#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-da ta">
<input type="hidden" name="folder" value="<cfoutput>#form.fol der#</cfou tput>">
<input type="file" name="FileToUpload"><br>
<input type="submit" name="submit" value="Upload">
</form>
</cfif>
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#">#descrip
</cfoutput>
</select>
<input type="submit" value="Go">
</form>
2nd page:
<cfif IsDefined("Form.Submit")>
<cfset FullPath = 'D:\inetpub\trappedinnyc\l
<!--- Uploading the file to the directory --->
<cffile destination="#FullPath#" action="upload" nameconflict="makeunique" filefield="FileToUpload">
<cfelse>
<form method="post" action="" enctype="multipart/form-da
<input type="hidden" name="folder" value="<cfoutput>#form.fol
<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(Get BaseTempla tePath())# media\#for m.folder#' >
Hope this makes sense ...
Regards!
eNTRANCE2002 :-)
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(Get
Hope this makes sense ...
Regards!
eNTRANCE2002 :-)
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.
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(GetBa seTemplate Path())>
<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 :-)
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(GetBa
<cfset FullPath = '#CurrentPath#media\#form.
<!--- 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 :-)
If so, you would need to include it as a hidden variable, form fields are not automatically passed from form to form.