Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 425263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:21:43+00:00 2026-05-12T19:21:43+00:00

I’m being stymied by what I thought would be the relatively simple task of

  • 0

I’m being stymied by what I thought would be the relatively simple task of creating functionality to allow users to upload a picture to a server directory and am looking for some help.

I have a simple form with a straightforward interface, passing a variable named ‘imagedata’ which is the data passed from a file input, a variable named ‘name’ which is a specified image name, and a variable named ‘imagetype’ which passes a file extension.

The code I’m using in the function (handler) to save this file is as follows:

<cfset form.imageName = form.name & "." & form.imagetype />
...
<cffile action="write" file="#sitepath#storage/bannerImages/#form.imagename#" output="#form.imageData#" />

This apparently won’t work; it will save a file with the correct name, but does not save the file correctly and doesn’t render as an image. I would think that this is something relatively simple, and I would think I’ve overlooked something because I’m not finding anything on google, which is odd. Help with this problem would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:21:43+00:00Added an answer on May 12, 2026 at 7:21 pm

    Don’t use action="write", use action="upload".

    Example:

    <cffile
        action       = "upload"
        fileField    = "ImageData"
        destination  = "/tmp/uploads"
        accept       = "image/jpg"
        nameConflict = "MakeUnique"
    />
    

    This will place the file in /tmp/uploads (use for example d:/tmp/uploads on Windows) – which is a directory not accessible online.

    At this point, you must verify that the file is what it claims to be – an image file of appropriate dimensions and filesize, and not a masked EXE nor embedded ZIP.

    Once you are happy the file is safe for hosting on your server, you can then move it to the appropriate directory and set the name to what was chosen.

    Something like…

    <cfif cffile.FileWasSaved>
    
        <cfset UploadedFileName = cffile.ServerDirectory & '/' & cffile.ServerFile />
    
        <cfif NOT IsImageFile( UploadedFileName )>
            <cfthrow message="Uploaded file not an image." />
        </cfif>
    
        <!--- INFO: Checks if zip embedded in image. --->
        <cftry>
            <cfzip action="list" file="#UploadedFileName#" name="tmp"/>
            <cfthrow message="Embedded zip files not allowed."/>
            <!--- TODO: Verify correct exception type for CF: --->
            <cfcatch type="java.util.zip.zipexception"></cfcatch>
        </cftry>
    
        <!---
            TODO: Validate any necessary business rules
            (e.g. image not too large, etc)
        --->        
    
    <cfelse>
        <cfthrow message="File Upload Error"/>
    </cfif>
    
    
    <cfif refind('\W',Form.Name)>
        <cfthrow message="Invalid Name specified. Only alphanumerics allowed."/>
    </cfif>
    <cfif NOT ListFindNoCase('PNG,JPG,GIF',Form.ImageType)>
        <cfthrow message="Invalid FileType specified. Must be PNG/JPG/GIF"/></cfif>
    </cfif>
    
    <cffile
        action      = "rename"
        source      = "#UploadedFileName#"
        destination = "#sitepath#storage/bannerImages/#Form.Name#.#Form.ImageType#"
    />
    

    That code is untested, and – as with everything you run on your servers, but especially so with code involving client uploads – make sure you understand what it is doing before using it.
    There is plenty of valuable information on Adobe LiveDocs and on the various CF blogs that is worth spending some time digesting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.