Solved

Image File Upload to ColdFusion Server

Posted on 2013-01-11
5
444 Views
Last Modified: 2013-01-13
Hi,
I have a page that will upload images using something similar to this :

<cfif isDefined("fileUpload")>
  <cffile action="upload"
     fileField="fileUpload"
     destination="C:\docs">
     <p>Thankyou, your file has been uploaded.</p>
</cfif>
<form enctype="multipart/form-data" method="post">
<input type="file" name="fileUpload" /><br />
<input type=text name="marketComment">
<input type="submit" value="Upload File" />
</form>

Open in new window


I do have a few other associated fields that are validated in this process. In this example I used a required field "marketComment".

If I need to redisplay the page because of an error (say the text field contained invalid characters),  I can redisplay the contents of the text field, but I don't seem to be able to redisplay the "chosen file" to upload.  The form field (form.fileUpload) only contains the location of the uploaded file on the CF server.

Is there a way to do this?  Or is this a Web security issue?

Thanks,
hefterr
0
Comment
Question by:hefterr
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:RickEpnet
ID: 38768114
Validate you form before it is submitted. I would use cfform instead of just a plain form.

Here is an example of a validation cfform.

<cfform action="unitedit.cfm" method="post" name="editatm" preloader="no">
<cfinput type="text" name="Account" message="Account Number is Required" required="yes" style="width: 100px;"maxlength="50">
<cfinput type="text" name="UNIT_ID" message="Unit ID is Required" required="yes" style="width: 100px;" maxlength="50">  
</cfform>
0
 
LVL 1

Author Comment

by:hefterr
ID: 38769265
Hi RickEpnet,
I was still wondering about my original question.  My boss doesn't like the popup edit messages.  We format our own.

hefterr
0
 
LVL 14

Assisted Solution

by:RickEpnet
RickEpnet earned 100 total points
ID: 38769445
I know of no way of doing that sorry. You can still format your own with JavaScript.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 400 total points
ID: 38770997
Rick is right. It's not possible. Browser's aren't allowed to "automatically" populate file fields. It would be extremely scary if they could because it would mean any web site could programatically upload files off your computer without your knowledge. So in a plain html page, files can only be attached by the user. It can't be done via code. Not without a special control like flash, activeX, etc..

Obviously not ideal. You could use ajax to submit and process the form, thus avoiding the issue because it wouldn't require leaving the page.

If that's not an option, you could upload the file anyway and save the fileName and path in session variables. Then kick the user back to the form with an error message. But instead of displaying a "file" input, display a label with the name of the saved file. Once everything is validated, just grab the saved file info from the session variables. Just be sure to clear out the variables once the submission is successful.
0
 
LVL 1

Author Closing Comment

by:hefterr
ID: 38771929
Thanks for the alternative ideas.
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question