Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error with Form

Status
Not open for further replies.

krichard

Technical User
Dec 5, 2001
41
US
Hello...

i want my code to automatically check to see if #RaceName# folder already exists, and if it doesn't, than i want it to create the new directory and add the file into that folder...

If it does exist just add that file to that folder...

This is what I have now...

<cfif #form.Image# NEQ &quot;&quot;>
<cffile action=&quot;upload&quot; filefield=&quot;Image&quot;
destination=&quot;D:\webserver\mtbmind.com\ACCEPT=&quot;image/jpg, image/pjpeg,image/gif,image/bmp, image/tiff&quot;
nameconflict=&quot;OVERWRITE&quot;
>


And i'm really not sure where to go from here... thanks for the help!
 
if you place some code like this above the your cffile tag then this will check to see if the directory exists on the server, if it does then it will continue to the upload, if not then it will create the directory for you then upload the file.

<CFSET directoryToUploadTo = &quot;D:\webserver\mtbmind.com\
<CFIF DirectoryExists(directoryToUploadTo) IS &quot;No&quot;>
<CFDIRECTORY ACTION=&quot;CREATE&quot; DIRECTORY=&quot;#variables.directoryToUploadTo#&quot;>
</CFIF>

.. your cffile code here

hope this helps!

Tony
 
Here is my code..

The correct link was inserted into my database, but the folder #RaceName# was never created!

<CFSET directoryToUploadTo = &quot;D:\webserver\mtbmind.com\
<CFIF DirectoryExists(directoryToUploadTo) IS &quot;No&quot;>
<CFDIRECTORY ACTION=&quot;CREATE&quot; DIRECTORY=&quot;#variables.directoryToUploadTo#&quot;>
</CFIF>

<cfif #form.Image# NEQ &quot;&quot;>
<cffile action=&quot;upload&quot; filefield=&quot;Image&quot;
destination=&quot;D:\webserver\mtbmind.com\ ACCEPT=&quot;image/jpg, image/pjpeg,image/gif,image/bmp, image/tiff&quot;
nameconflict=&quot;OVERWRITE&quot; >

<cfset file1 = #CFFILE.serverfile#>
<cfset img_path = 'Images/gallery/Races/#form.RaceName#/#file1#'>



<CFQUERY name=&quot;insertrequest&quot; DATASOURCE=&quot;#request.dsn#&quot;>
Insert Into RaceGallery
(
Image,
Description,
Region,
RaceName,
EntryDate
)
values
(
'#img_path#',
'#form.Description#',
'#getRegion.Region#',
'#form.RaceName#',
<cfoutput>#DateFormat(Now(),&quot;mm/dd/yyyy&quot;)# </CFOUTPUT>
)

</CFQUERY>
 
this is the code that I have just run against my server (Win2k, CF MX, IIS 5). Copy this and try it against your server.

<CFIF isDefined('Form.Submit')>
<CFPARAM NAME=&quot;Form.RaceName&quot; DEFAULT=&quot;22&quot;>
<CFSET directoryToUploadTo = &quot;D:\webserver\mtbmind.com\
<CFIF DirectoryExists(directoryToUploadTo) IS &quot;No&quot;>
<CFDIRECTORY ACTION=&quot;CREATE&quot; DIRECTORY=&quot;#variables.directoryToUploadTo#&quot;>
Creating the directory
</CFIF>

<CFFILE ACTION=&quot;UPLOAD&quot; FILEFIELD=&quot;Form.Image&quot; DESTINATION=&quot;#variables.directoryToUploadTo#&quot; NAMECONFLICT=&quot;OVERWRITE&quot; ACCEPT=&quot;image/jpg,image/pjpeg,image/gif,image/bmp,image/tiff&quot;>
</CFIF>

<html>
<head>
<title>Untitled</title>
</head>

<body>

<form name=&quot;asdf&quot; action=&quot;upload.cfm&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;>

<input type=&quot;file&quot; name=&quot;Image&quot;><BR><BR>

<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Upload&quot;>

</form>


</body>
</html>

What sort of information is going to be in the RaceName field? I am assuming that it is a number, but text will also be accepted, as long as it conforms to the normal directory naming rules

hope this helps!

Tony
 
Well whats interesting is you put all this code on the same pages as the form, when i had it in my action page.. does it matter???

What i am trying to do is, I already have a folder called races on my server, and for every race i want to have an individual folder that people can upload pics to...

so it would be Races folder/ #RaceName# folder /then #Image_file#, and the link to that would be stored in the database...

I tried putting your code above on the same page as my form, and then i put this:


<cfset file1 = #CFFILE.serverfile#>
<cfset img_path = 'Images/gallery/Races/#form.RaceName#/#file1#'>

on my action page....

This is my error...

Error Occurred While Processing Request
Element SERVERFILE is undefined in CFFILE.


The error occurred in D:\webserver\mtbmind.com\ line 11

9 :
10 :
11 : <cfset file1 = #CFFILE.serverfile#>
12 : <cfset img_path = 'Images/gallery/Races/#form.RaceName#/#file1#'>
13 :

--------------------------------------------------------------------------------
 


Can you try just putting my code into your/a new page and running that to see if we can get you server to create the directory.

what version of Coldfusion are you running?

Tony
 
I did try it, and i wrote down what error i got..

Error Occurred While Processing Request
Element SERVERFILE is undefined in CFFILE.


The error occurred in D:\webserver\mtbmind.com\ line 11

9 :
10 :
11 : <cfset file1 = #CFFILE.serverfile#>
12 : <cfset img_path = 'Images/gallery/Races/#form.RaceName#/#file1#'>
13 :
 
This code works, but I get an error with inserting the image path into the database...

Variable IMG_PATH is undefined.


The error occurred in D:\webserver\mtbmind.com\ line 52

50 : values
51 : (
52 : '#img_path#',
53 : '#form.Description#',
54 : '#getRegion.Region#',



<cfset folder = &quot;D:\webserver\mtbmind.com\
<cfif #form.Image# NEQ &quot;&quot; >

<cfif not DirectoryExists(folder)>
<cfdirectory action=&quot;Create&quot; directory=&quot;#folder#&quot;>
A folder was created for your request...
<p>
<cfelse>
<p>Our code determined this folder exists...
</cfif>

<cfset BaseDir = &quot;D:\webserver\mtbmind.com\
<cfdirectory action=&quot;list&quot;
directory=&quot;#BaseDir#&quot;
name=&quot;ImageGallery&quot;>

<cffile action=&quot;UPLOAD&quot;
destination=&quot;#folder#&quot;
nameconflict=&quot;Overwrite&quot;
filefield=&quot;Image&quot;>

<cfoutput>
<p> You uploaded the file <b>#file.clientfilename#.#file.clientfileext#</b>
successfully to:
<p> <b>#file.serverdirectory#\#file.serverfilename#.#file.serverfileext#.</b>
</cfoutput>

<cfset BaseDir = &quot;D:\webserver\mtbmind.com\
<cfdirectory action=&quot;list&quot;
directory=&quot;#folder#&quot;
name=&quot;ImageGallery&quot;>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top