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>
LVL 1
Todd VernonSenior Coldfusion DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pinaldaveCommented:
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
0
Tacobell777Commented:
Try
<CFFILE ACTION="upload" FILEFIELD="Photo" DESTINATION="Staff/" ACCEPT="*.jpg" NAMECONFLICT="Overwrite">
Without the form. in the filefield
0
Tacobell777Commented:
also, DESTINATION="Staff/"

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

C:\temp\whatever\
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

anandkpCommented:
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 : http://experts-exchange.com/Q_20663901.html
0
Todd VernonSenior Coldfusion DeveloperAuthor Commented:
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?
0
pinaldaveCommented:
http://www.ltsw.se/knbase/internet/mime.htp go this site and figured out which mime type you need to use.
0
Todd VernonSenior Coldfusion DeveloperAuthor Commented:
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?
0
anandkpCommented:
remove the "ACCEPT" attribute in ur code & then see ...
0
Todd VernonSenior Coldfusion DeveloperAuthor Commented:
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 "
0
pinaldaveCommented:
The file which you are uploading may be wrong... it is different then jpg... and that is pjpg....
0
mrichmonCommented:
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.
0
mrichmonCommented:
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.
0
Todd VernonSenior Coldfusion DeveloperAuthor Commented:
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?
0
mrichmonCommented:
which line is it on?
0
Todd VernonSenior Coldfusion DeveloperAuthor Commented:
The line with the CFFILE tag.
0
mrichmonCommented:
Can you print the exact error as it appears in the browser....
0
mosphatCommented:
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.
0
Todd VernonSenior Coldfusion DeveloperAuthor Commented:
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?
0
Tacobell777Commented:
it does not take an url, it takes a physical path of the filesystem, not the webserver
c:\whatever\cftest\Security\SecurityTeam\Staff\
0
Todd VernonSenior Coldfusion DeveloperAuthor Commented:
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>
0
Todd VernonSenior Coldfusion DeveloperAuthor Commented:
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.
0
Tacobell777Commented:
glad you finally figured it out without listening to any of the advice given to you..
0
moduloCommented:
PAQed with points refunded (250)

modulo
Community Support Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

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.