Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

waiting to upload

Explorer ,
Dec 19, 2008 Dec 19, 2008
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.
499
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 19, 2008 Dec 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 19, 2008 Dec 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 19, 2008 Dec 19, 2008
rmorgan wrote:
> I understand. But is there a way to just collect all information and just do
> everything at one time?

Sure, do it all with one 'form'. I put the word 'form' in quotes as it
does not have to be one 'page' to be one 'form. If you want to work up
a large, complex form into sections, that can be done with DHTML and|or
flash/flex based client code.

But looking at the code sample you originally provided you are already
doing this in multiple requests and server hits. Each and every page
with a <cfform...> tag on it is an independent request-response cycle
between the client and the server.

If you want to modify what you already have as little as possible, then
you just need to work with that the file has already been uploaded to
the server after step one, and it is sitting there waiting for the rest
of the steps to be completed. Nothing has to be done later to upload it
again. Just save it to some convenient location until the end.

You original question about somehow remembering the file upload control
until the end would actually result in unnecessary server hits. If this
was somehow possible, it would result in the file being uploaded after
step one and uploaded again at the end. Assuming that the HTTP standard
is not completely reworked.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 19, 2008 Dec 19, 2008
LATEST
Point taken.
If all else fails, change the thought process. I actually found some benefit by going ahead and letting it upload.
Thanks.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources