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

CFFILE UPLOAD does not always work

Status
Not open for further replies.

sfilipowicz

Programmer
May 8, 2007
9
NL
Hi Everyone,

On my website I have a form so that users can upload files. This works with about 99% of the users, unfortunetly some users experience problems when uploading, they get a IE error 'Page cannout be found' or somthing like that. This happens with several browsers and operting systems, so I have no clue where to start searching. The website is hosted at a hosting provider, if I place the upload form and page on my own CF server the users that has the problem at the hosting provider does not have the problem when on my server.
So to me it says that it's something on the server side but I just do not know what, because most people do not have this problem.

Any ideas?

CF Version on my own server : 7,0,2,142559
CF Version on my hostingprovider : CF MX 7 (that's all I know, is there some code I can run to get the exact version?)

Thanks for any help!

Regards,
Steven

CODE :

{UPLOAD FORM}
<html>
<body>


<form name="upload" action="upload_action.cfm" enctype="multipart/form-data" method="post">
<input type="File" name="uploadfile" style="width:220px;" class="button_1">
<input type="Submit" name="upload" value="Upload" class="button_1">
</form>

</body>
</html>


{UPLOAD PAGE}

<html>
<head>
<title>Untitled Document</title>

</head>
<body>

<cfset upload_images = "E:\Inetpub\



<cfset UniqueFileName = CreateUUID()>

<cffile action="upload" destination="#upload_images#" filefield="uploadfile" nameconflict="MakeUnique" >

<cffile action="rename" source="#upload_images##CFFile.ServerFile#" destination="#upload_images##UniqueFileName#.jpg">



File uploaded succesfully
<p>

<img src="<cfoutput>#UniqueFileName#.jpg</cfoutput>">
</body>
</html>
 
One problem I've found over time on some (l)Unix and Mac platforms is that there is a bunch of junk generated along with the form field. The only solution I've found is to trim the form field (there seems to be additional data from some OS's) try adding this before the upload:

Code:
  <cfset form.uploadfile = Trim(form.uploadfile) />

so you would get:

Code:
    <cfset UniqueFileName = CreateUUID()>
    <cfif Len(Trim(form.uploadfile))>
      <cfset form.uploadfile = Trim(form.uploadfile) />

      <cftry>

      <cffile action="upload" destination="#upload_images#"  filefield="uploadfile" nameconflict="MakeUnique" >
      <cffile action="rename" source="#upload_images##CFFile.ServerFile#" destination="#upload_images##UniqueFileName#.jpg">

         <cfcatch type="any">
           <span class="error_message">
             Sorry, something has gone wrong during your upload, a member of our Support Team has been notified.
           </span>
           <cfmail to="Me@MySite.com" from="error@MySite.com" subject="File Upload Error" type="HTML">
              <cfdump var="#cfcatch#" label="Mail Error" />
            </cfmail>
         </cfcatch>
      </cftry>
    <cfelse>
      <span class="error_message">
        Sorry, you didn't specify a file
      </span>
    </cfif>

We never fail, we just find that the path to succes is never quite what we thought...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top