Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / December 2004



Tip: Looking for answers? Try searching our database.

CFFile Wierdness

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill - 28 Dec 2004 19:35 GMT
I've got a form that includes an upload field, and the form also inserts
into a database. Everything works fine as long as there is a file being
uploaded. If there is no file being uploaded and the file field is blank, I
get an error saying "You have attempted to dereference a scalar variable of
type class java.lang.String as a structure with members."

The relevant code is shown below. Any ideas?

Bill

<cfif IsDefined("FORM.file") AND #FORM.file# NEQ "">
<cffile action="upload" filefield="file"
destination="D:\inetpub\Afolder\screens\" nameconflict="makeunique">
</cfif>
<cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "form1">
<cfset TheImage = File.ServerFile>
 <cfquery datasource="ADSN">
 INSERT INTO TCreateTicket (StationNumber, ProbDescription, Frequency,
StatusofProb,
 ScreenGrab, Nameofvictim)
VALUES (
 <cfif IsDefined("FORM.estation") AND #FORM.estation# NEQ "">
   '#FORM.estation#'
     <cfelse>
     NULL
 </cfif>
 ,
 <cfif IsDefined("FORM.edescription") AND #FORM.edescription# NEQ "">
   '#FORM.edescription#'
     <cfelse>
     NULL
 </cfif>
 ,
 <cfif IsDefined("FORM.efrequency") AND #FORM.efrequency# NEQ "">
   '#FORM.efrequency#'
     <cfelse>
     NULL
 </cfif>
 ,
 <cfif IsDefined("FORM.thestatus") AND #FORM.thestatus# NEQ "">
   '#FORM.thestatus#'
     <cfelse>
     NULL
 </cfif>
 ,
 <cfif IsDefined("FORM.file") AND #FORM.file# NEQ "">
   '#TheImage#'
     <cfelse>
     NULL
 </cfif>
 ,
 <cfif IsDefined("FORM.ename") AND #FORM.ename# NEQ "">
   '#FORM.ename#'
     <cfelse>
     NULL
 </cfif>
 )
 </cfquery>
Adam Cameron - 28 Dec 2004 20:27 GMT
> I've got a form that includes an upload field, and the form also inserts
> into a database. Everything works fine as long as there is a file being
[quoted text clipped - 3 lines]
>
> The relevant code is shown below. Any ideas?

Just for future reference, it would have been helpful if you'd mentioned
which LINE the error occurred on (and minimise the code you post, as most
of it is irrelevant to the problem).

But I suspect it is a conflict between this line:
<cffile action="upload" filefield="file"
destination="D:\inetpub\Afolder\screens\" nameconflict="makeunique">

And this line:

<cfset TheImage = File.ServerFile>

Two things:
1) "file" - as a reference to the structure returned by CFFILE ops - is
deprecated.  Use cffile.  eg: cffile.ServerFile.
2) I'm guessing CF is confusing the form-field called "file" and the
file-ops struct called "file", and thinking yuo're referencing the form
field (which will be a string).

Signature

Adam

PS: please note that posts made via the news feed (which I'm assuming
you're doing, as your message ain't on the web UI) are not making it to the
web UI @ present, so if you have more problems, it's probably best to post
them via the web UI, as your audience will be bigger.

Bill - 28 Dec 2004 21:04 GMT
The error is happening on this line:

<cfset TheImage = File.ServerFile>

> > I've got a form that includes an upload field, and the form also inserts
> > into a database. Everything works fine as long as there is a file being
[quoted text clipped - 31 lines]
> web UI @ present, so if you have more problems, it's probably best to post
> them via the web UI, as your audience will be bigger.
Bill - 28 Dec 2004 21:10 GMT
I changed file.serverfile to cffile.serverfile, and changed the form element
name from "file" to TheFile, and now I'm getting a different error:

Element SERVERFILE is undefined in CFFILE.

The error occurred in D:\inetpub\Afolder\trouble\tcreateticket.cfm: line 18

16 : <cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
17 : <cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ
"form1">
18 : <cfset TheImage = CFFile.ServerFile>
19 :   <cfquery datasource="ticketdsn">
20 :   INSERT INTO TCreateTicket (StationNumber, ProbDescription, Frequency,
StatusofProb,

> > I've got a form that includes an upload field, and the form also inserts
> > into a database. Everything works fine as long as there is a file being
[quoted text clipped - 31 lines]
> web UI @ present, so if you have more problems, it's probably best to post
> them via the web UI, as your audience will be bigger.
Bill - 28 Dec 2004 21:31 GMT
Nevermind. I moved line 18 elsewhere and it works fine now.

> I changed file.serverfile to cffile.serverfile, and changed the form element
> name from "file" to TheFile, and now I'm getting a different error:
[quoted text clipped - 49 lines]
> > web UI @ present, so if you have more problems, it's probably best to post
> > them via the web UI, as your audience will be bigger.
Adam Cameron - 28 Dec 2004 21:51 GMT
<cfif IsDefined("FORM.file") AND #FORM.file# NEQ "">
<cffile action="upload" filefield="file"
destination="D:\inetpub\Afolder\screens\" nameconflict="makeunique">
</cfif>

So the <cffile> op is only executed depending on form.file (form.thefile
now)...

> 16 : <cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
> 17 : <cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ
> "form1">
> 18 : <cfset TheImage = CFFile.ServerFile>

But this line of code will run even if the file op didn't take place (and
I'm guessing it didn't).

Stick a <cfdump var="#form#"> @ the top of the template, and <cfdump
var="#cffile#"> immediately after the <cffile> tag.  And <cfabort> before
you get to the erroring line.

I suspect your form is passing something other than what you think.

Signature

Adam

Bill - 28 Dec 2004 22:17 GMT
Thanks Adam. Your fresh perspective helped me figure it out.

Bill

> <cfif IsDefined("FORM.file") AND #FORM.file# NEQ "">
> <cffile action="upload" filefield="file"
[quoted text clipped - 21 lines]
>
> Adam
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.