views:

58

answers:

2

I have a form that contains an html file browse button ( <input type=file /> ). User select a file by clicking browse button and submit the form. On form submission new php script (submitToServer.php) is called that use that file to upload it to the server.

Now I want to upload that file without using browse button because file name and path is always same when we upload. How can I do this?

currently submitToServer.php file handle file using browse button like this:

$errorCode = $_FILES['claimsfile']['error'];
$claimsFileLocation = $_FILES["claimsfile"]["tmp_name"];
$claimsFileName = $_FILES["claimsfile"]["name"];
$claimsFilePointer = fopen($_FILES["claimsfile"]["tmp_name"], "r");
+3  A: 

I suspect that's not possible due to security reasons, you do have to click the browse button and specify a file first. Pre-filling this field with some tricky paths (../../etc) and not pressing the browse button would have created security problems (if you could imagine for a while)

Sarfraz
Ok. If I cant do this without browse button then can I use any trick to fill browse text field with required path on a button click event.
Awan
@Awan: As i said you can't, you do have to click the browse button.
Sarfraz
Absolutely not possible without activex/java/flash.
Joonas Trussmann
@Awan nope. If such a trick existed, it would be a security hole and quickly patched by browser vendors.
Pekka
You can use DragDrop to upload the file. This would save you the click, but the user had to drop it in the browser window, so it's probably the same.
nikic
+2  A: 

You can't. HTML does not allow it for security reasons.

The only way to control which file is uploaded from serverside would be to use an applet (java, activeX, flash) - and even then you'll need to use signed code to get out of the sandbox.

C.

symcbean
Not even Flash is allowed to do this without showing a "select file" dialog I think.
Pekka