CFFILE UPLOAD ENCTYPE ERROR

No matter what I do, I can't seem to locate the error that's causing this.  I commented out the DIV set where the form resides in case it was creating an issue with the error, but still keep getting the same error. I've spent nearly 3 hours combing through my code and still no resolve.

ERROR:

Invalid content type: ''.  
The cffile action="upload" requires forms to use enctype="multipart/form-data".  
 
The error occurred in C:\domains\restorationlutherancom\admin\photo_uploads.cfm: line 31
 
29 :   <cffile action="upload"
30 :      fileField="ifile"
31 :      destination="C:\domains\restorationlutheran\images\tempUpload\" nameconflict="makeunique" accept="image/jpeg">
32 :             <cfif cffile.filesize gt 200 * 1024>
33 :         <cffile action="delete" file="C:\domains\restorationlutheran\images\tempUpload\#cffile.serverfile#">
 


<cfparam name="url.area" default="home_slides">
<cfparam name="url.imgid" default="">
<cfparam name="form.area" default="#url.area#">
<cfparam name="form.ifile" default="">
<cfparam name="err1" default="">
<cfparam name="c1" default="">
<cfif url.area is "home_slides">
<cfset idesc="JPG Format - 72dpi, 850px wide by 233px tall">
<cfdirectory action="list" directory="c:\domains\restorationlutherancom\images\user\rot\" sort="asc" name="il" filter="*.jpg">
<cfset ip="/images/user/rot/">
<cfset cip="\images\user\rot\">
<cfset sti=1>
<cfelseif url.area is "home_buttons">
<cfset idesc="JPG format - 72dpi, 240px wide by 180px tall">
<cfdirectory action="list" directory="c:\domains\restorationlutherancom\images\buttons\" sort="asc" name="il" filter="*.jpg">
<cfset ip="/images/buttons/">
<cfset cip="\images\buttons\">
<cfset sti=1>
<cfelseif url.area is "article">
<cfset idesc="JPEG format - 72dpi, 240px wide by 180px tall">
<cfdirectory action="list" directory="c:\domains\restorationlutherancom\images\articles\" sort="asc" name="il" filter="*.jpg">
<cfset ip="/images/articles/">
<cfset cip="\images\articles\">
<cfset sti=0>
</cfif>
<cfparam name="idesc" default="">

<cfif isDefined("ifile")>
  <cffile action="upload"
     fileField="ifile"
     destination="C:\domains\restorationlutheran\images\tempUpload\" nameconflict="makeunique" accept="image/jpeg">
		<cfif cffile.filesize gt 200 * 1024>
        <cffile action="delete" file="C:\domains\restorationlutheran\images\tempUpload\#cffile.serverfile#">
        <cfset err1="The file you uploaded exceeded 150kb. Please ensure the file meets the upload requirements.">
        <cfelse>
        <cfset c1="The file was uploaded.">
        </cfif>
</cfif>
<!doctype html>
<html  lang="en">
  <head>
  <meta charset="utf-8">
 <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" />
<title>RLC - Admin - Photo Upload Page</title>
<!--- <script src="includes/SpryCollapsiblePanel.js" type="text/javascript"></script>
<link href="includes/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" /> --->
<link href="http://www.restorationlutheran.com/includes/css/admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>
</head>

<body>

<!--- <div id="CollapsiblePanel1" class="CollapsiblePanel">
  <div class="CollapsiblePanelTab" tabindex="0"><h1>IMAGE ADMIN PAGE</h1></div>
  <div class="CollapsiblePanelContent"> --->
<FORM method="post" enctype="multipart/form-data">  
  <table width="100%" border="0" cellspacing="0" cellpadding="3" class="black12">
  <tr>
    <td width="14%" align="right" bgcolor="#CCCCCC">Select Area of Site:</td>
    <td colspan="2" bgcolor="#CCCCCC">
      <select name="area" id="area" onchange="MM_jumpMenu('parent',this,0)">
        <option value="http://www.restorationlutheran.com/admin/photo_uploads.cfm?area=home_slides"<cfif url.area is "home_slides"> selected="selected"</cfif>>Home Slideshow</option>
        <option value="http://www.restorationlutheran.com/admin/photo_uploads.cfm?area=home_buttons"<cfif url.area is "home_buttons"> selected="selected"</cfif>>Home Buttons</option>
        <option value="http://www.restorationlutheran.com/admin/photo_uploads.cfm?area=article"<cfif url.area is "article"> selected="selected"</cfif>>Article Image</option>
      </select><CFOUTPUT>* #idesc#</CFOUTPUT></td>
    </tr>
  <tr>
    <td align="right" valign="top">Existing Images:<br>
      <hr /><cfif sti is 1>Please select an image to replace<cfelse>Please upload a new image according to the specifications listed for this area of the site. If the image you want is already displayed to the right, there is no need to duplicate the upload. Please use the ARTICLE ADMIN PAGE to select that image for your article.</cfif>
      </td>
    <td colspan="2"><div id="uploaded_images"><cfif il.recordcount gt 0><cfoutput query="il"><a href="http://www.restorationlutheran.com/admin/photo_uploads.cfm?area=#url.area#&imgid=#ip##name#"><img src="http://www.restorationlutheran.com#ip##name#?#randrange(1,400)#" class="thumbs"  <cfif url.imgid is "#ip##name#">style="border:4px red solid"</cfif>/></a></cfoutput><cfelse><h2>THERE ARE NO IMAGES TO DISPLAY AT THIS TIME</h2></cfif></div>
      </td>
  </tr>
<cfif form.ifile is "" AND err1 is "">
  <tr>
    <td align="right" nowrap="nowrap" bgcolor="#CCCCCC">Select File to Be Uploaded:</td>
    <td width="36%" bgcolor="#CCCCCC">
      <input type="file" name="ifile" id="ifile" /></td>
    <td width="50%" bgcolor="#CCCCCC">&nbsp;</td>
  </tr>
<cfelseif not err1 is "">
<tr>
    <td align="right" nowrap="nowrap" bgcolor="#CCCCCC">Select File to Be Uploaded:</td>
    <td width="36%" bgcolor="#CCCCCC">
      <input type="file" name="ifile" id="ifile" /><cfoutput>#err1#</cfoutput></td>
    <td width="50%" bgcolor="#CCCCCC">&nbsp;</td>
  </tr>
<cfelseif not c1 is "">
<tr><td colspan="2">#c1#</td></tr>
</cfif>
  <tr>
    <td align="right">&nbsp;</td>
    <td><input type="submit" name="button" id="button" value="upload image" /><INPUT name="imgname" type="hidden" value="<CFOUTPUT>#url.imgid#</CFOUTPUT>" /></td>
    <td>&nbsp;</td>
  </tr>
</table>
</FORM>
<!--- </div>
</div>

<script type="text/javascript">
var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel1");
</script> --->
</body>
</html>

Open in new window

LVL 1
day6Asked:
Who is Participating?
 
_agx_Connect With a Mentor Commented:
> <cfif isDefined("ifile")>

The problem is line 28.  Because you already defined that variable on line 4:

              <cfparam name="form.ifile" default="">

The variable always exists. So CF tries to run the upload code before anything is uploaded, causing the error you see. To fix it, add an extra check to make sure the variable isn't empty and it should work correctly.

ie
           <cfif isDefined("form.ifile") AND len(trim(form.ifile))>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.