Skip to main content
Known Participant
September 12, 2009
Question

How can I upload an .jpg file to server from browser?

  • September 12, 2009
  • 2 replies
  • 1033 views

Hi!

I am trying to create a webpage whereby myself or any one of my managers can easily create an e-mail & send to our client database. I would like to be able to upload an image to be included with the email, which I have been trying to do using <cffile>, but I get an error message:

Security: The requested template has been denied access to http:\***MY WEB ADDRESS****.

I'm assuming that this is an issue with my hosting server, but I fail to see a way round it as I cannot add ftp login data to a <cffile> tag.

I have also tried to do the same thing with <cfftp> tag including the ftp login data, but this returns an error whereby the website cannot access the file from my hard drive.

Does anyone have a solution?

    This topic has been closed for replies.

    2 replies

    Inspiring
    September 14, 2009

    BKBK's code should work! If you created directory  c:\uploads\images\ and you still can not make it work my assumption is you have problem with permissions! Check with your hosting provider or if you have access to CF control panel permissions details,if you did not already you should grant some permissions (read, write, modify, read&execute, file listing, etc.) for that path( c:\uploads\images\).

    BKBK
    Community Expert
    Community Expert
    September 13, 2009

    What does your code look like? Something like this?

    <cfif isDefined("form.image") >
        <cffile action = "upload"
            fileField = "image"
            destination = "c:\uploads\images"
            accept = "image/jpg,image/pjpeg,image/jpeg"
            nameConflict = "MakeUnique">
            Done uploading image!

    <!--- Put the code to send email here including, for example, c:\uploads\images\#cffile.serverfile# as attachment --->
    <cfelse>
        <cfform method="post" action="#cgi.script_name#"
            name="uploadForm" enctype="multipart/form-data">
            <cfinput name="image" type="file">
            <br><br>
            <cfinput name="submit" type="submit" value="Upload image">
        </cfform>
    </cfif>

    Known Participant
    September 13, 2009

    I have been playing with the code so much that it wouldn't help at all!

    This is a completely new area for me and so I need basic step-by-step instructions.

    I tried copying and pasting the code into my webpage (updating the data for my file & server) but still no luck!

    Please help me!!!!

    BKBK
    Community Expert
    Community Expert
    September 13, 2009

    Forget about the email part for the moment. First try to get the uploading to work.

    What do you mean by " still no luck"? Did you create the directory, c:\uploads\images\ on the server? The code requires it.