Solved

Upload file without selecting it?

Posted on 2004-04-07
6
371 Views
Last Modified: 2013-12-24
Hi

I have two files:
form.cfm
----------
<form action="reg.cfm" method="post" name="frmBedomning" id="frmBedomning" enctype="multipart/form-data" >
<input type="File" name="NewFile" size=20 value="C:\q_<cfoutput>#id#</cfoutput>.wav">
<input type="submit" value="Upload file">
</form>

NOTICE: Notice the #id# inside the input File field.

reg.cfm
---------
<cfif isdefined("Form.NewFile")>
      <cfset CurrentDir=GetDirectoryFromPath(ExpandPath("*.*"))>
      <cffile
            action="upload"
            filefield="NewFile"
            destination="#CurrentDir#/files/"
            accept="*/*"
            nameconflict="MakeUnique">

      <cfoutput>    
            File Uploaded:#File.ClientFile#<br>
            File was Overwritten?:#File.FileWasOverwritten#<br>  
            File Saved:#File.ServerFile#<br>    
      </cfoutput>
</cfif>

When I test this I get an error like this:
The form field "NewFile" did not contain a file.

Is there a workaround to this problem? I don't want to browse for the file every time I want to upload it to the server...instead I want to write it's name and location in some way...
Can this be done?
//Tom
 
0
Comment
Question by:tombombadilll
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:shooksm
ID: 10774402
It is a behaviour of the browser that you can not change.  You can not set the value of INPUT tag of the type FILE.  That would be a big security hole if you were able too.  Just think, what would keep me from uploading local files on your pc without you even knowing it?  All I would have to do is create a hidden form, specify a particular common file in the value of the file input box and submit the form with some javascript, like after the page finishes loading.  So I am afraid you are stuck with that behaviour if you are serving the page remotely.

I am not 100% sure but I think you can used HTAs and have a little more flexability.  But these have to be local files on the pc and not served from a remote source to negate the security.
0
 
LVL 9

Accepted Solution

by:
shooksm earned 250 total points
ID: 10774511
Here is a little more info:

http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/value_6.asp

Or most importantly "The property is read-only. The property has no default value".
0
 

Author Comment

by:tombombadilll
ID: 10774548
ok...thanks for the answer...
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 35

Expert Comment

by:mrichmon
ID: 10775465
Well one alternative is that the first time you browse to the file you can store it in a session or client variable and then look at your session/client variable and if there is a value there then ask the user if they want to use that as a default or browse a new file to upload....
0
 
LVL 9

Expert Comment

by:shooksm
ID: 10775500
mrichmon, the value property is read only.  It can only be modified by the user clicking on the browse button.  Which would make storing the information pointless since you can not give that input box a value.
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10775627
I realize that it is read only.

What I was suggesting was that the first time you upload the file you keep track of it.  Then if you needed it for the future - you just access the one on the server instead of re-uploading it again - because you have saved information to your variable about the location you first uploaded it to the server.

Of course if the file changes and you are trying to access a new copy then it really isn't the same file - it is a different file with the same name - so you would have to have the user re-browse to it.

It was just something to consider depending on how that file will be used in the application.  FOr example, if it will be used as an email attachment maybe you only need to upload it once to the server and then you come back next week and want to send that message again - you can access the file on the server instead of needing to re-upload it.

My comment wasn't a way to populate the input value because, as you said shooksm,  - it is read only.  It was just another method that may help limit the need to continually upload a file depending on the use of the uploaded file.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
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…
This video discusses moving either the default database or any database to a new volume.

757 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

22 Experts available now in Live!

Get 1:1 Help Now