Skip to main content
Participant
February 2, 2008
Question

file upload fails as tmp filename is returned

  • February 2, 2008
  • 3 replies
  • 824 views
My problem is I cant upload a file using form input and cffile upload functionality. The returned file is always something like:
C:\CFusionMX7\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp48497.tmp

I have broken it down as much as possible to figure it out, leaving only a form input field for the file,
and a page which simply outputs the form data. It can be tested here:
http://daus.mediadogs.net/debug/

This is index.cfml :

<html>
<head><title>form problem</title></head>
<body>
<h1>Form problem: file returns as tmp name.</h1>
<cfform name="new_field" action="submit.cfml" method="POST" enctype="multipart/form-data">
<input type="file" name="filename"/>
<input type="submit" value="Upload file"/>
</cfform>
</body>
</html>

this is submit.cfml:

<html>
<head>
<title>Submit page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<cfoutput>
<cfdump var="#form#">
This file was chosen: #form.filename#
</cfoutput>
</body>
</html>
---
I have tested both with cfform and normal form, no luck. Appreciate all help !

    This topic has been closed for replies.

    3 replies

    Participant
    February 3, 2008
    Thanx Azadi, you were absolutely right.
    Inspiring
    February 3, 2008
    your mistake is thinking that #form.filename# will contain the name of
    selected file after the form is submitted.
    that is not so. as you have seen yourself, it instead contains a
    reference to the emp file created on the server after upload.
    CFFILE then moves this temp file to your designated destination folder.
    the name of uploaded file is then available to you as
    #cffile.clientfile#. CFFILE scope also contains other very useful
    variables - look it up in the docs if you are not familiar with it.

    hth

    ---
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com
    Inspiring
    February 2, 2008
    Do it this way...

    Here is your input field

    <cfinput type="file" name="menupic1" message="Please select an Image File
    (Small)" required="yes" id="menupic1">

    Here is the code from your submit page. You will need to adjust this line to
    your needs and the accept option in the cffile
    <cfset uploadDirectory = mid(currentDirectory,1,lenstring-6) &
    "images\productimages\">
    prodimage is the variable of you file name including the path

    <!--- Get where the file is going to go --->
    <cfoutput>
    <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath())>
    <cfset lenstring = len(GetDirectoryFromPath(GetTemplatePath()))>
    <cfset uploadDirectory = mid(currentDirectory,1,lenstring-6) &
    "images\productimages\">
    </cfoutput>

    <!--- Upload the file --->
    <cffile accept="image/pjpeg, image/jpeg" action = "upload"
    destination = "#uploadDirectory#"
    fileField = "menupic1"
    nameConflict = "makeunique" result="mfile1">
    <cfset prodimage = uploadDirectory & mfile1.serverfile>



    "PsychoFreud" <webforumsuser@macromedia.com> wrote in message
    news:fo2cbl$b8m$1@forums.macromedia.com...
    > My problem is I cant upload a file using form input and cffile upload
    > functionality. The returned file is always something like:
    > C:\CFusionMX7\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp48497
    > .tmp I have broken it down as much as possible to figure it out, leaving
    > only
    > a form input field for the file, and a page which simply outputs the form
    > data.
    > It can be tested here: http://daus.mediadogs.net/debug/ This is
    > index.cfml :
    > <html> <head><title>form problem</title></head> <body> <h1>Form problem:
    > file returns as tmp name.</h1> <cfform name='new_field'
    > action='submit.cfml'
    > method='POST' enctype='multipart/form-data'> <input type='file'
    > name='filename'/> <input type='submit' value='Upload file'/> </cfform>
    > </body> </html> this is submit.cfml: <html> <head> <title>Submit
    > page</title> <meta http-equiv='Content-Type' content='text/html;
    > charset=iso-8859-1' /> </head> <body> <cfoutput> <cfdump var='#form#'>
    > This file was chosen: #form.filename# </cfoutput> </body> </html> --- I
    > have tested both with cfform and normal form, no luck. Appreciate all
    > help !
    >