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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cfc & cffile woes

Status
Not open for further replies.

digitalcreationz

Programmer
Oct 6, 2002
2
AU
good old cffile..cfmx
Here is the delimma, . I'm back with the vehicle application, recoding it towards a cfc, xml ideal in mind, but for some reason now I'm having an issue.

and it's with the infamous tag cffile.
For some reason it's adding the file name to the database as a path, where it wasn't doing it before.


Code:
<cffunction name=&quot;addVehicle&quot; access=&quot;public&quot; returntype=&quot;boolean&quot; displayname=&quot;Add a Vehicle&quot; hint=&quot;Returns a boolean value whether it processed or not.&quot;> 
<!--- Verify the Image for the vehicle is present, if so rename the server variable to .serverfile --->
<cfif IsDefined(&quot;form.vImages&quot;) AND Len(form.vImages)> 
<cftry><!--- C:\inetpub\mathiesonmotors\uploaded_Images\Image-full --->
<cffile action=&quot;upload&quot; filefield=&quot;vImages&quot; destination=&quot;C:\CFusionMX\[URL unfurl="true"]wwwroot\math\uploaded_Images\Image-full\&quot;[/URL] nameconflict=&quot;makeunique&quot;>
<cfcatch type=&quot;all&quot;>
</cfcatch>
</cftry>
<cfset vImages = cffile.serverfile >
</cfif>
<!--- Verify the Thumbnail for the vehicle is present, if so rename the server variable to .serverfile ---> 
<cfif IsDefined(&quot;form.vThumb&quot;) AND Len(form.vThumb)>
<cftry><!--- C:\inetpub\mathiesonmotors\uploaded_Images\Image-thumb --->
<cffile action=&quot;upload&quot; filefield=&quot;vThumb&quot; destination=&quot;C:\CFusionMX\[URL unfurl="true"]wwwroot\math\uploaded_Images\Image-thumb\&quot;[/URL] nameconflict=&quot;makeunique&quot;>
<cfcatch type=&quot;all&quot;>
</cfcatch>
</cftry>
<cfset vThumb = cffile.serverfile>
</cfif>

<cftry>
<!--- Insert into the database. Also to note the trim() so it's taking away the extra padding --->
<cfquery datasource=&quot;vehicle2.mdb&quot;>
INSERT INTO vehicle2 (vRegno, vYear, vType, vMake, vModel, vColor, vExtras, 
vEngine, vImages, vThumb, vKms, vCondition, vFuel, vPrice, vOnroads, vPerweek, 
vPowerW, vPowerS, vLowQ, vTrans) VALUES ('#trim(form.vRegno)#','#FORM.vYear#','#FORM.vType#','#FORM.vMake#',
'#trim(form.vModel)#','#trim(form.vColor)#','#trim(form.vExtras)#','#trim(form.vEngine)#','#trim(form.vImages)#','#trim(form.vThumb)#','#trim(form.vKms)#'
, '#FORM.vCondition#', '#FORM.vFuel#', '#trim(form.vPrice)#', '#trim(form.vOnroads)#', '#trim(form.vPerweek)#', '#FORM.vPowerW#'
, '#FORM.vPowerS#', '#FORM.vLowQ#', '#FORM.vTrans#') 
</cfquery>
<cfreturn true>
<cfcatch type=&quot;any&quot;>
<cfreturn false>
</cfcatch>
</cftry>
</cffunction>

That is the query I'm using .. I've also tried using the cffile.serverFileName in the cfset tags.

It's been a while so I could be mistaken, . but I thought that cffile.serverfile saved the actual file? But what it's actually saving in the database is C:/CFusionMX/runtime/servers/default/SERVER-INF/temp/ a full path, .. I can't see how or why this is happening, .. can anyone enlighten me?


Is it because I'm doing this with a cfc?, I mean that &quot;can't&quot; be the issue, hell how is everyone doing it?
Robby
by the way, . this is how I'm passing it from my action template.

Code:
<!--- Set defaults for the checkboxes on the add a vehicle page.--->
<cfparam name=&quot;form.vPowerS&quot; default=&quot;no&quot;>
<cfparam name=&quot;form.vPowerW&quot; default=&quot;no&quot;>
<cfparam name=&quot;form.vLowQ&quot; default=&quot;no&quot;>
<!--- Initiate the component and send all of the realevant data to &quot;that&quot; component ---> 

<cfset vehicleObj = createObject(&quot;component&quot;, &quot;#fubar#.vehicle&quot;)>
<cfset rs=vehicleObj.addVehicle(vRegno, vYear, vType, vMake, vModel, vColor, vExtras, 
vEngine, vImages, vThumb, vKms, vCondition, vFuel, vPrice, vOnroads, vPerweek, 
vPowerW, vPowerS, vLowQ, vTrans)>

<cfdump var=&quot;#rs#&quot;>

C:\CFusionMX\runtime\servers\default\SERVER-INF\temp\ in the addressbar isn't a working path, and I have updater 2 installed.
 
Hmmmm... so #CFFILE.serverFile# contains a full path??

That shouldn't be right. ServerFile should ONLY contain the filename (no path info at all). I always have to use
Code:
<CFOUTPUT>#CFFILE.ServerDirectory#/#CFFILE.ServerFile#</CFOUTPUT>
to even figure out where the file is.

Perhaps the problem isn't with ServerFile, but how your function is set up. You seem to be improperly mixing straight variable names and form.variablenames.

For example,
Code:
<cfif IsDefined(&quot;form.vThumb&quot;) AND Len(form.vThumb)>
   <cftry>
     <cffile action=&quot;upload&quot; filefield=&quot;vThumb&quot; destination=&quot;C:\CFusionMX\[URL unfurl="true"]wwwroot\math\uploaded_Images\Image-thumb\&quot;[/URL] nameconflict=&quot;makeunique&quot;>
     <cfcatch type=&quot;all&quot;>
     </cfcatch>
   </cftry>
   <cfset vThumb = cffile.serverfile>
</cfif>

are you sure you don't mean:
Code:
<cfif IsDefined(&quot;form.vThumb&quot;) AND Len(form.vThumb)>
   <cftry>
     <cffile action=&quot;upload&quot; filefield=&quot;vThumb&quot; destination=&quot;C:\CFusionMX\[URL unfurl="true"]wwwroot\math\uploaded_Images\Image-thumb\&quot;[/URL] nameconflict=&quot;makeunique&quot;>
     <cfcatch type=&quot;all&quot;>
     </cfcatch>
   </cftry>
   <cfset
Code:
form.
Code:
vThumb = cffile.serverfile>
</cfif>

since that's what you're inserting into your database:

Code:
INSERT INTO vehicle2 (vRegno, vYear, vType, vMake, vModel, vColor, vExtras, 
vEngine, vImages, vThumb, vKms, vCondition, vFuel, vPrice, vOnroads, vPerweek, 
vPowerW, vPowerS, vLowQ, vTrans) VALUES ('#trim(form.vRegno)#','#FORM.vYear#','#FORM.vType#','#FORM.vMake#',
'#trim(form.vModel)#','#trim(form.vColor)#','#trim(form.vExtras)#','#trim(form.vEngine)#','#trim(form.vImages)#','#trim(
Code:
form.
Code:
vThumb)#','#trim(form.vKms)#'
, '#FORM.vCondition#', '#FORM.vFuel#', '#trim(form.vPrice)#', '#trim(form.vOnroads)#', '#trim(form.vPerweek)#', '#FORM.vPowerW#'
, '#FORM.vPowerS#', '#FORM.vLowQ#', '#FORM.vTrans#')
Hope it helps,
-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top