5 Replies Latest reply on Aug 6, 2006 12:35 AM by Abinidi

    cffile and uploading images

    Level 7
      I am a little bit confused on creating a form that can upload an image to a
      folder. I am using the cffile tag and have a file field on the form to allow
      the user to browse and file a logo to upload. I have it all set up but do I
      use the copy or upload?

      I have this:
      <cffile action="copy" accept="jpg,jpeg,png,gif,psd" destination="logos"
      filefield="logo" nameconflict="makeunique"> but then I noticed the 'upload'
      attribute to the action.

      Thanks
      --
      Wally Kolcz
      Developer / Support


        • 1. Re: cffile and uploading images
          Level 7
          Figured it out. However I have another question.
          How can I just capture just the name of the file and not the complete path?


          • 2. Re: cffile and uploading images
            Abinidi Level 1
            Cffile.Serverfile will return filename and extension
            cffile.serverfileext will return file extension only
            cffile.serverfilename will only return filename without extension

            Also, do a CFDUMP on CFFILE afterwards to see all the option you can use.
            • 3. Re: cffile and uploading images
              Level 7
              Thanks for the heads up on these. I have been searching the docs, but I
              can't find an example on how to use them. I want to use te cffile.serverfile
              to return the file name and extension. Do I use that during the upload
              process? If so, how to you add it to the statement?

              <cffile action="upload" accept="image/gif, image/jpeg, image/jpg, image/png,
              image/psd" destination="E:\webs\website.com\main\clients\logos"
              filefield="form.logo" nameconflict="makeunique">

              would it be:

              <cffile.serverfile action="upload" accept="image/gif, image/jpeg, image/jpg,
              image/png, image/psd" destination="E:\webs\website.com\main\clients\logos"
              filefield="form.logo" nameconflict="makeunique">


              • 4. Re: cffile and uploading images
                Level 7
                Ok, I gathered that it is not how you use it. I see how you can use it to
                show the file name in an <cfoutput>

                How can I use this parameter to ensure that only the filename and extension
                are being entered into the database? Would I use that in the INSERT
                statement?

                Thanks.


                • 5. Re: cffile and uploading images
                  Abinidi Level 1
                  Yes.
                  Do your query as such:

                  <cfquery datasource="DSN">
                  Insert into Tablename(image_name)
                  Values('#cffile.serverfile#")
                  </cfquery>

                  Adjust to what your db tables, etc are called.