Welcome to Dream.In.Code
Getting Help is Easy!

Join 107,708 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,099 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



in ColdFusion, upload a file whose name is retrieved from a db

 
Reply to this topicStart new topic

in ColdFusion, upload a file whose name is retrieved from a db

algodfried
post 19 Jan, 2008 - 07:05 PM
Post #1


New D.I.C Head

*
Joined: 19 Jan, 2008
Posts: 3

I have searched everywhere for a way to use cffile to upload a file. The catch is that I have file names stored in a database and want to upload the file without having to browse or type the file name into a cfinput type=file for use in a cffile tag. I can't find how to preload the name into the file input tag. The code for the form is:
CODE

<script Language=JavaScript>

function UploadPhoto(vFileName){
    document.forms.UploadPhoto.FileName.text = vFileName;
    document.forms.UploadPhoto.submit();

}
</Script>

<cfelseif isdefined("form.UploadPhoto")>
  <cfoutput>
    <cfform name="UploadPhoto"action="uploadfile.cfm"
        enctype="multipart/form-data" method=post>
        <cfinput name="FileName" size=50 type="file" />
       <cfinput name="SubmitForm"
             type=submit value="Upload the File" />
    </cfform>
    <script Language=JavaScript>
      UploadPhoto("#form.PictureFileName#");
    </Script>
  </cfoutput>
</cfif>


Where uploadfile.cfm contains a typical cffile tag and form.PictureFileName is a text input field with the full path and filename of the file to upload.

The UploadPhoto function submits the form the way I want it to but there seems to be no way to preload the filename into the file input tag.
User is offlineProfile CardPM

Go to the top of the page


skyhawk133
post 19 Jan, 2008 - 11:04 PM
Post #2


Head DIC Head

Group Icon
Joined: 17 Mar, 2001
Posts: 14,432



Thanked 33 times

Dream Kudos: 1650

Expert In: Web Development

My Contributions


does adding value="test.txt" to the cfinput make test.txt appear??

If so, you should be able to just run a cfquery then put value="#queryname.filename#"

Let me know if that doesn't make sense, it's late and I'm pretty tired.
User is offlineProfile CardPM

Go to the top of the page

jayman9
post 19 Jan, 2008 - 11:13 PM
Post #3


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,300



Thanked 21 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


It would seem that it should according to the reference docs.

cfinput reference
User is offlineProfile CardPM

Go to the top of the page

algodfried
post 20 Jan, 2008 - 08:02 AM
Post #4


New D.I.C Head

*
Joined: 19 Jan, 2008
Posts: 3

QUOTE(algodfried @ 19 Jan, 2008 - 07:05 PM) *

I have searched everywhere for a way to use cffile to upload a file. The catch is that I have file names stored in a database and want to upload the file without having to browse or type the file name into a cfinput type=file for use in a cffile tag. I can't find how to preload the name into the file input tag. The code for the form is:
CODE

<script Language=JavaScript>

function UploadPhoto(vFileName){
    document.forms.UploadPhoto.FileName.text = vFileName;
    document.forms.UploadPhoto.submit();

}
</Script>

<cfelseif isdefined("form.UploadPhoto")>
  <cfoutput>
    <cfform name="UploadPhoto"action="uploadfile.cfm"
        enctype="multipart/form-data" method=post>
        <cfinput name="FileName" size=50 type="file" />
       <cfinput name="SubmitForm"
             type=submit value="Upload the File" />
    </cfform>
    <script Language=JavaScript>
      UploadPhoto("#form.PictureFileName#");
    </Script>
  </cfoutput>
</cfif>


Where uploadfile.cfm contains a typical cffile tag and form.PictureFileName is a text input field with the full path and filename of the file to upload.

The UploadPhoto function submits the form the way I want it to but there seems to be no way to preload the filename into the file input tag.

User is offlineProfile CardPM

Go to the top of the page

algodfried
post 20 Jan, 2008 - 08:10 AM
Post #5


New D.I.C Head

*
Joined: 19 Jan, 2008
Posts: 3

I continued to look on the web this morning and found a post on "theScripts.com" that addresses this problem. Apparently, most web browsers do not support the value attribute of a file input field for security reasons. The browsers want the user to browse or type the filename so that a bad guy can't copy files from a client machine without the user's participation. This is bad for me because it prevents me from providing a single click way to upload a file whose name is already known. If anyone knows a work-around, please let me know.

The link to the post is http://www.thescripts.com/forum/thread564351.html.
User is offlineProfile CardPM

Go to the top of the page

skyhawk133
post 20 Jan, 2008 - 10:13 AM
Post #6


Head DIC Head

Group Icon
Joined: 17 Mar, 2001
Posts: 14,432



Thanked 33 times

Dream Kudos: 1650

Expert In: Web Development

My Contributions


Hmmm, interesting, I was unaware of that.

Could you rename the file on the backend after it's been uploaded. i.e. run the cffile mode=upload then do a cffile mode=move to rename the file to the desired name?
User is offlineProfile CardPM

Go to the top of the page

sansclue
post 21 Jan, 2008 - 06:35 PM
Post #7


D.I.C Head

**
Joined: 21 Nov, 2007
Posts: 82



Thanked 4 times
My Contributions


algodfried,

Unless you go the way of using a signed applet, activeX control, etc. you are pretty much out of luck. It has been that way with browsers as long as I can remember. While your intentions may be good, it would be a very bad thing if browsers did not have this restriction. Imagine what spammers alone could do with it wink2.gif

You could use the cffile.client(...) variables to get additional information, after you upload the file. But obviously that will not help you with your current dilemma.

Best of Luck

This post has been edited by sansclue: 21 Jan, 2008 - 06:38 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/30/08 03:00AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month