Solved

Upload file without selecting it?

Posted on 2004-04-07
6
410 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
What You Need to Know when Searching for a Webhost Provider
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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