6 Replies Latest reply on Feb 3, 2008 5:37 PM by ACS LLC

    Processing uploaded files

    ACS LLC Level 1
      I need to upload photos to a site, I want to make sure that they are only JPG files uploaded, plus restrict the size.

      Is there anyway to check the filesize and type before uploading? Or can somebody upload a 20meg EXE file that would hog our bandwidth?

      Also, how do I check the file extension to make sure it's JPG? When I look at it I get TMP, and if I save it I seem to have to specify an extension?

      Thanks

      Mark
        • 1. Re: Processing uploaded files
          Akbarsait N
          Hi ACS LLC,

          Please use the following reference sites. You can check the size of the file once the file uploaded or during the time of upload also and then you have to set custom message to user regarding the size of the file.

          Reference 1: Checks the file size once uploaded
          http://www.bennadel.com/blog/670-Ask-Ben-Limit-File-Upload-Size-In-ColdFusion.htm

          Reference 2: The check is performed before uploading the file
          http://tutorial120.easycfm.com/

          And to ensure the file type you need to use another attribute in CFFILE tag called accept = "image/jpg"

          Akbarsait
          Chennai ColdFusion UserGroup, India
          http://akbarn.wordpress.com/
          • 2. Re: Processing uploaded files
            ACS LLC Level 1
            Thanks.

            The filesize check was very handy (I should have figured that out myself from the DOCs)

            The only issue I have is with accept = .. problem is that if I only accept JPG's it appears to throw a CF error if anything but that is uploaded.. is there a way to pick this up so I can process the error appropriately?

            Thanks

            Mark
            • 3. Re: Processing uploaded files
              ACS LLC Level 1
              I actually came across another issue

              We upload two images from the previous page, so by checking the cgi content size it does not work because if we want to restrict to 100k per file it actually adds up both images, so it was have a 95k and an 80k both are technically acceptable, but the total is under 100k for each. I could make it stop at 200k , but that then allows users to manipulate the upload, they could upload a 190k and go back and upload another 190k in the 2nd picture.

              I was also just told by somebody that is still uploads the file in order to get the file size?

              Mark
              • 4. Re: Processing uploaded files
                Level 7
                ACS LLC wrote:
                > Thanks. The filesize check was very handy (I should have figured that out
                > myself from the DOCs) The only issue I have is with accept = .. problem is
                > that if I only accept JPG's it appears to throw a CF error if anything but that
                > is uploaded.. is there a way to pick this up so I can process the error
                > appropriately? Thanks Mark
                >

                use cftry/cfcatch - details are in the docs


                ---
                Azadi Saryev
                Sabai-dee.com
                http://www.sabai-dee.com
                • 5. Re: Processing uploaded files
                  Level 7
                  ACS LLC wrote:
                  > I actually came across another issue We upload two images from the previous
                  > page, so by checking the cgi content size it does not work because if we want
                  > to restrict to 100k per file it actually adds up both images, so it was have a
                  > 95k and an 80k both are technically acceptable, but the total is under 100k for
                  > each. I could make it stop at 200k , but that then allows users to manipulate
                  > the upload, they could upload a 190k and go back and upload another 190k in the
                  > 2nd picture. I was also just told by somebody that is still uploads the file
                  > in order to get the file size? Mark
                  >

                  in your case i would probably:
                  [all the below on the action page, obviously]
                  1) check the CGI.CONTENT_LENGTH to see if it is significantly larger
                  than ([allowed file size]x[number of files being uploaded])+[size of
                  form page]
                  2) if it is NOT significantly larger then use CFFILE.FILESIZE after each
                  upload (in a cfloop, presumably) to check exact size of each file and
                  delete the ones found to be too large.

                  hth


                  ---
                  Azadi Saryev
                  Sabai-dee.com
                  http://www.sabai-dee.com
                  • 6. Re: Processing uploaded files
                    ACS LLC Level 1
                    Good idea.

                    I was told however that to get that CGI variable that the server has to upload anyway, so nothing gained. I am testing locally right now so that is difficult to disprove. I'll try some code on the server and upload a LARGE file

                    Thanks

                    Mark