Solved

Upload file without selecting it?

Posted on 2004-04-07
6
401 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

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

Suggested Solutions

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 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