Link to home
Start Free TrialLog in
Avatar of Todd Vernon
Todd VernonFlag for United States of America

asked on

CFFILE Upload Question

I'm trying to get this application to work properly, and can't.  The CFFILE Upload for the Photo is the only thing that isn't working.  Form.cfm is the page that submits everything to Insert.cfm page.  The essential parts of the code for both pages is listed below.

<!---(Form.cfm) --->
<FORM ACTION="Insert.cfm" ENCTYPE="multipart/form-data" METHOD="POST" NAME="EC" ONSUBMIT="return ErrorCheck();">
   <TABLE ALIGN="center" BGCOLOR="000066" BORDER="0" WIDTH="350">  
   <TR>
      <TD BGCOLOR="CCCCFF" VALIGN="top" STYLE="padding:1px;">
         <TABLE>
         <TR>
            <TD ALIGN="left" CLASS="ContentLarge" WIDTH="140">
      <B>ADMIN
            </TD>
            <TD ALIGN="left" WIDTH="210">
               <INPUT TYPE="TEXT" CLASS="Content" MAXLENGTH="1" NAME="Admin" SIZE="1">
            </TD>
         </TR>
         <TR>
            <TD ALIGN="left" CLASS="ContentLarge">
                  <B>LAST NAME
            </TD>
            <TD ALIGN="left" WIDTH="150">
               <INPUT TYPE="TEXT" CLASS="Content" MAXLENGTH="20" NAME="LastName" SIZE="23">
            </TD>
         </TR>
         <TR>
            <TD ALIGN="left" CLASS="ContentLarge">
               <B>FIRST NAME
            </TD>
            <TD ALIGN="left">
              <INPUT TYPE="TEXT" CLASS="Content" MAXLENGTH="20" NAME="FirstName" SIZE="23">
            </TD>
         </TR>
         <TR>
            <TD ALIGN="left" CLASS="ContentLarge">
                <B>WORK PHONE
            </TD>
            <TD ALIGN="left">
                <INPUT TYPE="TEXT" CLASS="Content" MAXLENGTH="12" NAME="WorkPhone" SIZE="23">
            </TD>
         </TR>
         <TR>
            <TD ALIGN="left" CLASS="ContentLarge">
      <B>EMAIL
            </TD>
            <TD ALIGN="left">
      <INPUT TYPE="TEXT" CLASS="Content" MAXLENGTH="30" NAME="Email" SIZE="23">
            </TD>
         </TR>
         <TR>
            <TD ALIGN="left" CLASS="ContentLarge">
      <B>PHOTO
            </TD>
            <TD ALIGN="left">
      <INPUT TYPE="File" CLASS="Box" MAXLENGTH="100" NAME="Photo" SIZE="18">
            </TD>
         </TR>
         </TABLE>
      </TD>
   </TR>
   </TABLE>
   <TABLE ALIGN="center">
   <TR>
      <TD ALIGN="center">
         <BR>
         <INPUT TYPE="Button" VALUE="Back" ONCLICK="history.go(-1)" onmouseover="highlightButton('Button')" onmouseout="highlightButton('')" onmousedown="this.style.fontStyle='italic'" ONMOUSEUP="this.style.fontStyle=('')">&nbsp;
         <INPUT TYPE="Submit" VALUE="Submit" onmouseover="highlightButton('Button')" onmouseout="highlightButton('')" onmousedown="this.style.fontStyle='italic'" ONMOUSEUP="this.style.fontStyle=('')"><BR>
      </TD>
   </TR>
   </TABLE>
</FORM>



<!---(Insert.cfm) --->
<CFQUERY NAME="qAdd" DATASOURCE="#request.datasource#" username="#request.username#" password="#request.password#">
INSERT INTO #request.prefix#.t_securityteam (Admin, LastName, FirstName, WorkPhone, Email, Photo)
VALUES('#Form.Admin#','#Form.LastName#','#Form.FirstName#','#Form.WorkPhone#','#Form.Email#','#Form.Photo#')
</CFQUERY>
<P ALIGN="center">The new member is entered into the Security Team database!
<P ALIGN="center">You will be redirected back to the Security Team Admin webpage in a few seconds. If not click button below to return.
<FORM>
   <INPUT TYPE="Button" VALUE="Security Team Admin" ONCLICK="parent.location='SecurityTeamAdmin.cfm'" onmouseover="highlightButton('start')" onmouseout="highlightButton('')" onmousedown="this.style.fontStyle='italic'" ONMOUSEUP="this.style.fontStyle=('')">
</FORM>
<TABLE WIDTH="500">  
<TR>
   <TD ALIGN="center" CLASS="Heading">
      The data you entered was:
   </TD>
</TR>       
</TABLE>
<TABLE WIDTH="500">
<TR>
   <TD ALIGN="right">
      <CFOUTPUT>
      <TABLE WIDTH="425">
      <TR>
         <TD ALIGN="left" CLASS="ContentLarge" WIDTH="175">
            ADMIN
         </TD>
         <TD ALIGN="left" CLASS="ContentLarge" WIDTH="250">
           #Form.Admin#
         </TD>
      </TR>
      <TR>
         <TD ALIGN="left" CLASS="ContentLarge">
             LAST NAME
         </TD>
         <TD ALIGN="left" CLASS="ContentLarge">
            #Form.LastName#
         </TD>
      </TR>
      <TR>       
         <TD ALIGN="left" CLASS="ContentLarge">
             FIRST NAME
         </TD>
         <TD ALIGN="left" CLASS="ContentLarge">
            #Form.FirstName#
         </TD>
      </TR>
      <TR>       
         <TD ALIGN="left" CLASS="ContentLarge">
            WORK PHONE
         </TD>
         <TD ALIGN="left" CLASS="ContentLarge">
            #Form.WorkPhone#
         </TD>
      </TR>
      <TR>
         <TD ALIGN="left" CLASS="ContentLarge">
            EMAIL
         </TD>
         <TD ALIGN="left" CLASS="ContentLarge">
            #Form.Email#
         </TD>
      </TR>
      <TR>
         <TD ALIGN="left" CLASS="ContentLarge">
            PHOTO
         </TD>
         <TD ALIGN="left" CLASS="ContentLarge">
            <CFFILE ACTION="upload" FILEFIELD="Form.Photo" DESTINATION="Staff/" ACCEPT="*.jpg" NAMECONFLICT="Overwrite">
             Content Type: #File.ContentType#<BR>
             Content SubType: #File.ContentSubType#<BR>
             Client Directory: #File.ClientDirectory#<BR>
             Client File: #File.ClientFile#<BR>
             Client FileName: #File.ClientFileName#<BR>
             Client FileExt: #File.ClientFileExt#<BR>
             Server Directory: #File.ServerDirectory#<BR>
             Server File: #File.ServerFile#<BR>
             Attempted ServerFile: #File.AttemptedServerFile#<BR>
             File Existed? #File.FileExisted#<BR>
             File Was Saved? #File.FileWasSaved#<BR>
             File Was Overwritten? #File.FileWasOverWritten#<BR>
             File Was Renamed? #File.FileWasRenamed#<BR>
         </TD>
      </TR>
      </TABLE>
      </CFOUTPUT>
   </TD>
</TR>       
</TABLE>
Avatar of pinaldave
pinaldave
Flag of India image

you should ask this question in the TA of ColdFusion.
Also, what is the error? where is the error? please post when you move it to CF area.
Regards,
---Pinal
Avatar of Tacobell777
Tacobell777

Try
<CFFILE ACTION="upload" FILEFIELD="Photo" DESTINATION="Staff/" ACCEPT="*.jpg" NAMECONFLICT="Overwrite">
Without the form. in the filefield
also, DESTINATION="Staff/"

needs to be a full path to the directory you want to upload to, i.e.

C:\temp\whatever\
I think u shld be uploading the file first with the CFFILE Tag & then inserting the filename [#file.serverfile#] - in ur query ...

for more info wrt what i am talking abt - refer : https://www.experts-exchange.com/questions/20663901/Users-uploading-pictures.html
Avatar of Todd Vernon

ASKER

Thank you, I got a lot of great responses from everybody. However, none were correct, or at least at this time they are not.  To be a bit more clear the record IS getting added to the Team page.  So the Insert is working and the employee is entered into the database.  However, the Photo field is not getting added. That is what I'm asking for help on.  I'm getting the following error

"The MIME type of the uploaded file "image/pjpeg" was not accepted by the server."

Any ideas?
http://www.ltsw.se/knbase/internet/mime.htp go this site and figured out which mime type you need to use.
I know which MIME type to use.  It's either "*.jpg" or "image/jpeg".  I've tried both and I get the same error "The MIME type of the uploaded file "image/pjpeg" was not accepted by the server."  

Notice the "p" before the "jpeg"   No wonder it's not getting accepted.  There is no extra "p" in my code.  So where is it coming from?
remove the "ACCEPT" attribute in ur code & then see ...
Well that takes out Security Controls that we will need, so I don't like that idea.  However, in interest of getting the App up and running, I did remove it.  Now, I'm getting the following error:

"String index out of range: -3 "
The file which you are uploading may be wrong... it is different then jpg... and that is pjpg....
There is a bug with the mime type of image/jpeg.  It actually does not accept all valid jpeg images.  The solution is to remove the mime type restriction and then set up your own manual restriction by examining the file extention and determining if it is a file extension type you will allow.
The bug is basically in the accept portion of the cffile.  It also happens for *.jpg

I know you said you don't like the removal of the security, but that is why I recommended your own manual form of security.
Ok, like I said, the MIME type has  been removed (By the way, pinaldave, the file was a correct image).  Now then, what is this "String index out of range: -3 " error?  That has to be something else... what, I don't know?  Could it be the length of the filename?
which line is it on?
The line with the CFFILE tag.
Can you print the exact error as it appears in the browser....
String index out of range happens because you didn't used a full path for the destination argument. It needs to be a full path, like Tacobell777 already mentioned.
Conflicting answers here...  I put the whole path in, and got an error again.  I tried it a number of different ways, like without the HTTPS:, with backward slashes, with forward slashes, etc.  However, I was able to fix it... I think.

I seemed to get rid of that error when I put the following path \\myurl.com\cftest\Security\SecurityTeam\Staff\ like this.  Ok fine.  No errors.  Still no photograph though!  When I go to the Team.cfm page to click on the persons photo, it opens up mycomputer and is looking at my local computer some how.  

So I went to the Edit.cfm page and the path is listed as:
C:\CFusionMX\runtime\servers\default\SERVER-INF\temp\wwwroot-tmp\neotmp29915.tmp  Now I know for sure that is not what I uploaded.  I loaded a picture from the FSU/Duke football game, and that ain't it.  So what's going on?
it does not take an url, it takes a physical path of the filesystem, not the webserver
c:\whatever\cftest\Security\SecurityTeam\Staff\
Ok, I figured it out with the help of an Applications analyst here at work.  
Key Issue #1: is the CFFILE tag stayed in the Insert.cfm page, however it had to be moved BEFORE the query.  
Key Issue #2: The FILEFIELD="Form.Photo" was correct the way I originally had it.
Key Issue #3: The DESTINATION="#request.image_path#" was changed to neither a relative NOR absolute URL.  It was changed to a variable that was to be accessed from the application.cfm page.  That way we could use some CFSET's to determine whether it was in Dev, QA, or Production.  


<!---Application.cfm--->
<!---Image Path--->
<CFAPPLICATION NAME="image_path">
<CFSWITCH EXPRESSION="#cgi.server_name#">
   <CFCASE VALUE="mtndev1.motown.lmco.com">
      <CFSET request.image_path="\\#cgi.server_name#\cftest\security\SecurityTeam\Staff\">
   </CFCASE>
   <CFCASE VALUE="mtnappsqa.motown.lmco.com">
      <CFSET request.image_path="\\#cgi.server_name#\cftest\SecurityTeam\Staff\">
   </CFCASE>
   <CFCASE VALUE="mtnappsprod.motown.lmco.com">
      <CFSET request.image_path="\\#cgi.server_name#\cftest\SecurityTeam\Staff\">
   </CFCASE>
</CFSWITCH>

<!---(Form.cfm) --->
<FORM ACTION="Insert.cfm" ENCTYPE="multipart/form-data" METHOD="POST" NAME="EC" ONSUBMIT="return ErrorCheck();">                        
<TABLE ALIGN="center">
<TR>
   <TD ALIGN="center" CLASS="Heading">
      All Fields <FONT COLOR="FF0000">MUST</FONT> Be Filled In
   </TD>                                                         </TR>
</TABLE>
<TABLE ALIGN="center" BGCOLOR="000066" BORDER="0" WIDTH="350">  
<TR>
   <TD BGCOLOR="CCCCFF" VALIGN="top" STYLE="padding:1px;">
      <TABLE>
      <TR>
            <TD ALIGN="left" CLASS="ContentLarge" WIDTH="140">
     <B>ADMIN
            </TD>
            <TD ALIGN="left" WIDTH="210">
              <INPUT TYPE="TEXT" CLASS="Content" MAXLENGTH="1" NAME="Admin" SIZE="1">
            </TD>
         </TR>
         <TR>
            <TD ALIGN="left" CLASS="ContentLarge">
                  <B>LAST NAME
            </TD>
            <TD ALIGN="left" WIDTH="150">
              <INPUT TYPE="TEXT" CLASS="Content" MAXLENGTH="20" NAME="LastName" SIZE="23">
            </TD>
         </TR>
         <TR>
            <TD ALIGN="left" CLASS="ContentLarge">
               <B>FIRST NAME
            </TD>
            <TD ALIGN="left">
             <INPUT TYPE="TEXT" CLASS="Content" MAXLENGTH="20" NAME="FirstName" SIZE="23">
            </TD>
         </TR>
         <TR>
            <TD ALIGN="left" CLASS="ContentLarge">
               <B>WORK PHONE
            </TD>
            <TD ALIGN="left">
               <INPUT TYPE="TEXT" CLASS="Content" MAXLENGTH="12" NAME="WorkPhone" SIZE="23">
            </TD>
         </TR>
         <TR>
            <TD ALIGN="left" CLASS="ContentLarge">
     <B>EMAIL
            </TD>
            <TD ALIGN="left">
     <INPUT TYPE="TEXT" CLASS="Content" MAXLENGTH="30" NAME="Email" SIZE="23">
            </TD>
         </TR>
         <TR>
            <TD ALIGN="left" CLASS="ContentLarge">
      <B>PHOTO
            </TD>
           <TD ALIGN="left">
      <INPUT TYPE="File" CLASS="Box" MAXLENGTH="120" NAME="Photo" SIZE="18">
           </TD>
        </TR>
        </TABLE>
     </TD>
</TR>                                                         </TABLE>                                                          <TABLE ALIGN="center">
<TR>
   <TD ALIGN="center">
      <BR>
      <INPUT TYPE="Button" VALUE="Back" ONCLICK="history.go(-1)" onmouseover="highlightButton('Button')" onmouseout="highlightButton('')" onmousedown="this.style.fontStyle='italic'" ONMOUSEUP="this.style.fontStyle=('')">&nbsp;
      <INPUT TYPE="Submit" VALUE="Submit" onmouseover="highlightButton('Button')" onmouseout="highlightButton('')" onmousedown="this.style.fontStyle='italic'" ONMOUSEUP="this.style.fontStyle=('')"><BR>
   </TD>
</TR>
</TABLE>
</FORM>


<!---(Insert.cfm) --->

<TABLE WIDTH="500">
<TR>
   <TH CLASS="Heading">
      <CFFILE ACTION="upload" FILEFIELD="form.Photo" DESTINATION="#request.image_path#" NAMECONFLICT="Overwrite">
      <CFQUERY NAME="qAdd" DATASOURCE="#request.datasource#" username="#request.username#" password="#request.password#">
      INSERT INTO #request.prefix#.t_securityteam (Admin, NTID, LastName, FirstName, WorkPhone, CellPhone, HomePhone, Pager, Fax, MailStop, Email, Photo)
      VALUES ('#Form.Admin#','#Form.NTID#','#Form.LastName#','#Form.FirstName#','#Form.WorkPhone#','#Form.CellPhone#','#Form.HomePhone#','#Form.Pager#','#Form.Fax#','#Form.MailStop#','#Form.Email#','Staff/#File.ServerFile#')
      </CFQUERY>
      <P ALIGN="center">The new member is entered into the Security Team database!
      <P ALIGN="center">You will be redirected back to the Security Team Admin webpage in a few seconds. If not click button below to return.
      <FORM>
       <INPUT TYPE="Button" VALUE="Security Team Admin" ONCLICK="parent.location='SecurityTeamAdmin.cfm'" onmouseover="highlightButton('start')" onmouseout="highlightButton('')" onmousedown="this.style.fontStyle='italic'" ONMOUSEUP="this.style.fontStyle=('')">
      </FORM>
   </TH>
</TR>
<TR>
   <TD ALIGN="center" CLASS="Heading">
      The data you entered was:
   </TD>
</TR>       
</TABLE>
<TABLE WIDTH="500">  
<TR>
   <TD ALIGN="center" CLASS="Heading">
      The data you entered was:
   </TD>
</TR>      
</TABLE>
<TABLE WIDTH="500">
<TR>
   <TD ALIGN="right">
      <CFOUTPUT>
      <TABLE WIDTH="425">
      <TR>
         <TD ALIGN="left" CLASS="ContentLarge" WIDTH="175">
            ADMIN
         </TD>
         <TD ALIGN="left" CLASS="ContentLarge" WIDTH="250">
           #Form.Admin#
         </TD>
      </TR>
      <TR>
         <TD ALIGN="left" CLASS="ContentLarge">
             LAST NAME
         </TD>
         <TD ALIGN="left" CLASS="ContentLarge">
            #Form.LastName#
         </TD>
      </TR>
      <TR>      
         <TD ALIGN="left" CLASS="ContentLarge">
             FIRST NAME
         </TD>
         <TD ALIGN="left" CLASS="ContentLarge">
            #Form.FirstName#
         </TD>
      </TR>
      <TR>      
         <TD ALIGN="left" CLASS="ContentLarge">
            WORK PHONE
         </TD>
         <TD ALIGN="left" CLASS="ContentLarge">
            #Form.WorkPhone#
         </TD>
      </TR>
      <TR>
         <TD ALIGN="left" CLASS="ContentLarge">
            EMAIL
         </TD>
         <TD ALIGN="left" CLASS="ContentLarge">
            #Form.Email#
         </TD>
      </TR>
      <TR>
         <TD ALIGN="left" CLASS="ContentLarge">
            PHOTO
         </TD>
         <TD ALIGN="left" CLASS="ContentLarge">
            #Form.Photo#
         </TD>
      </TR>
      </TABLE>
      </CFOUTPUT>
   </TD>
</TR>       
</TABLE>
Also if you notice the value in the CFQUERY for Photo was changed to 'Staff/#File.ServerFile#' So you no longer see the Temp file that it was sending up, you see the actual name of the image.  Also the ACCEPT attribute of the CFFILE tag was put back in and works fine.
glad you finally figured it out without listening to any of the advice given to you..
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial