Skip to main content
July 14, 2010
Question

file type check before uploading a file

  • July 14, 2010
  • 1 reply
  • 1107 views

Right now I have a processing page that uploads a file only of type zip. If you try submitting something other than a zip file, it throws an error. Is it possible to check the file type before uploading?

Something like this in pseudo code:

if (file type does not = zip ) {

     redirect to the homepage with cflocation

}

else {

     <cffile action="upload" ....  />

}

    This topic has been closed for replies.

    1 reply

    ilssac
    Inspiring
    July 14, 2010

    Not with ColdFusion, it does not run on the client and has no idea about the file until the client browser has sent it to the web server and the web server as put it into the server's temp directory.

    Maybe with someting that runs on the client, like JavaScript.  But when dealing with files in the client browser you quickly run into security features that prevent you from doing much to prevent hackers from writing client code to farm unsupecting users systems for interesting files.

    July 14, 2010

    well i was already gong to validate the file type in JS on the client. But if the user disables JS and submits a file type other than zip, the processing page will throw a nice big CF error. What is the best way to handle this on the server side?

    ilssac
    Inspiring
    July 14, 2010

    Trap the error with <cftry><cfcatch>, or any of the other ColdFusion expecption handling features, and present the users with a nice pretty error message.