Skip to main content
Inspiring
December 19, 2008
Question

waiting to upload

  • December 19, 2008
  • 1 reply
  • 563 views
Within my app I am giving the users the ability to upload a file. On a page I have the <cfinput type="file" name="imagefile" > for the user to select a file, then they will click next to go on to the next page to continue providing information. How do I need to set things up so that when the user finally gets to the last page and clicks "finished" the file will upload? If I put the <cfinput type="file" name="imagefile" > on the last page before the finished button it works fine, but when I put it several pages back it looses it mind and does not know what to do.

Page with file input box:
<cfform>
<cfinput type="file" name="imagefile" >
</cfform>

Next page:
<cfif isdefined("form.imagefile")>
<cfset Session.imagefile ='#form.imagefile#'>
<cfelse>
<cfset Session.imagefile = "">
</cfif>
<cfform method="post" action="finished.cfm" enctype="multipart/form-data">
BLAH BLAH
</cfform>

Finished page:
I get this error:The form field someimagename.jpg did not contain a file.
Finished page code.
<cfif isDefined("Session.imagefile") and #Session.imagefile# neq "" >
<cffile action = "upload" fileField = "#Session.imagefile#" destination = "#ExpandPath("testimages")#" nameConflict = "MakeUnique" accept="image/jpg, image/jpeg, image/pjpeg, image/gif">
</cfif>

Again, if I put the file selection input back to back with the finished page it works fine, but due to certain other internal issues, it needs to be several pages back from the finished page.
    This topic has been closed for replies.

    1 reply

    Inspiring
    December 19, 2008
    rmorgan wrote:
    >
    > Again, if I put the file selection input back to back with the finished page
    > it works fine, but due to certain other internal issues, it needs to be several
    > pages back from the finished page.
    >

    You are running against the nature of HTTP request-responses and web
    servers. When you go to the next page, I presume with some type of form
    submittal action., the browser uploads the file to the web server then
    and there and the web server puts it into a temporary location. If you
    don't do something with it immediately, it is going to be forgotten.

    What you need to realize that where you have this line <cfif
    isDefined("form.imagefile")>... that for this to be true, the file has
    *already* been uploaded to the server. You need to follow this up with
    a <cffile action="upload"....> tag that takes the file from the web
    servers temporary location and put it somewhere where you can work on
    it. Put the results of that into your session variable and move on with
    your application. When you get to the last step you can get the file
    from where you put it and do whatever needs to be done with it.
    rmorganAuthor
    Inspiring
    December 19, 2008
    I understand. But is there a way to just collect all information and just do everything at one time? I would like to limit server hits as much as possible. By waiting until the end and make db insertions and uploads and just doing everything in one single motion is what I would like to do.