Solved

Image File Upload to ColdFusion Server

Posted on 2013-01-11
5
438 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the alternative ideas.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Cold Fusion Regular Expression 8 64
looping over JSON Object and insert into query 3 50
<cfquery> to Excel 5 48
Database set up 5 60
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 …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now