• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

Upload file without selecting it?

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
tombombadilll
Asked:
tombombadilll
  • 3
  • 2
1 Solution
 
shooksmCommented:
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
 
shooksmCommented:
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
 
tombombadilllAuthor Commented:
ok...thanks for the answer...
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
mrichmonCommented:
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
 
shooksmCommented:
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
 
mrichmonCommented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now