Solved

Image File Upload to ColdFusion Server

Posted on 2013-01-11
5
442 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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