Solved

Upload file without selecting it?

Posted on 2004-04-07
6
380 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
Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
URL redirect 4 51
Htaccess - if subdomain "dev." 2 74
Is it true tt IIS7 can't support TLSv1.2 if OS is on Win2008 1 56
WEB Farm 6 64
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 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

12 Experts available now in Live!

Get 1:1 Help Now