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

Urgent not recognizing cfif

Status
Not open for further replies.

izachar

Technical User
Oct 7, 2000
84
0
0
CA
I am using this code
<CFSET thisPath= ExpandPath(&quot;*.*&quot;)>
<CFSET imgDirectory= GetDirectoryFromPath(thisPath)>

<CFIF IsDefined(&quot;FORM.p_picture&quot;)>
<CFTRY>
<!--- Upoad File --->
<CFFILE ACTION=&quot;UPLOAD&quot;
FILEFIELD=&quot;FORM.p_picture&quot;
DESTINATION=&quot;#imgDirectory#&quot;
NAMECONFLICT=&quot;Overwrite&quot;
ACCEPT=&quot;image/pjpeg,image/jpeg,image/gif&quot;>

<!--- Rename Img --->
<CFFILE ACTION=&quot;RENAME&quot;
SOURCE=&quot;#CFFILE.ServerDirectory#\#CFFILE.ServerFile#&quot;
DESTINATION=&quot;#CFFILE.ServerDirectory#\pictures\pic#p_id#.#CFFILE.ServerFileExt#&quot;>
<cfset picture=&quot;pic#p_id#.#CFFILE.ServerFileExt#&quot;>

<!--- Catch error, if it's not a jpg or gif file --->
<CFCATCH TYPE=&quot;Any&quot;>
I'm sorry, you must upload a .gif or .jpg file.
</CFCATCH>
</CFTRY>
</CFIF>
</cfoutput>

and if I do not send anything through the form it does not apply the isdefined condition hence giving me an error.
Users might want to update just the name without having to upload the picture again. How can I tell the upload and the query to ignor the field if it is not there?????
 
Do you have the form attribute 'enctype=&quot;multipart/form-data&quot;' in your form, as

<form action=&quot;...&quot; enctype=&quot;multipart/form-data&quot; method=&quot;POST&quot;>
John Hoarty
jhoarty@quickestore.com
 
if p_picture is the name of the file input tag, try using it without &quot;form&quot;, e.g.:

<CFIF IsDefined(&quot;p_picture&quot;)>


in my application, I have solve this problem using evaluate function:

<cfif Evaluate(&quot;#p_picture#&quot;) EQ &quot;&quot;>

... Sylvano
dsylvano@hotmail.com

&quot;every and each day when I learn something new is a small victory...&quot;
 
I tried both solutions and they did not work. If nothing is inputed isn't the value of p_picture=&quot;&quot; ? So I tries IsDefined(&quot;p_picture&quot;) neq &quot;&quot; but it still did not work. Any idea????
 
If I remember correctly, if there is no input, the form variable is not defined. If you want to test for it, just use IsDefined(&quot;p_picture&quot;) or NOT IsDefined(&quot;p_picture&quot;). I usually try to avoid negative logic, but sometimes it's the simplest way. Calista :-X
Jedi Knight,
Champion of the Force
 
what is the error cf is returning? Sylvano
dsylvano@hotmail.com

&quot;every and each day when I learn something new is a small victory...&quot;
 
Coding:
<CFIF IsDefined(&quot;FORM.p_picture&quot;) NEQ &quot;&quot;>

is really coding:
<CFIF YES NEQ &quot;&quot;>
or
<CFIF No NEQ &quot;&quot;>

Which will always result to TRUE.

You need to do it this way:
<CFIF IsDefined(&quot;FORM.p_picture&quot;) AND FORM.p_picture NEQ &quot;&quot;> - tleish
 
The error is in the query not in the upload. But I know it is running through the code since the cfcatch gets triggered.
 
why don't u use cfparam to save the default as &quot;&quot;,

<cfparam name=&quot;file&quot; default=&quot;&quot;>

 
I used <CFIF IsDefined(&quot;FORM.p_picture&quot;) AND FORM.p_picture NEQ &quot;&quot;> it worked I just needed to pull those fileds from the db and if they were not defined to reuse the existing info so it does not get erased when it does the update.

Thank you all for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top