Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get $_FILES["inputID"]["tmp_name"] from a file field using javascript?

I have an input field:

<input type="file" id="inputID" name="file">

When a button is clicked to submit, a JavaScript function will run (url: upload.php). I need to be able to access $_FILES["inputID"]["tmp_name"] from this input field so that I could use it on upload.php as,

move_uploaded_file($_FILES["inputID"]["tmp_name"], $target_file)

Is this possible?
At the moment, I get an error:

Notice: Undefined index: inputID

Any help would be very much appreciated.

Thanks so much! :-)

like image 696
Mary Avatar asked Jul 14 '15 05:07

Mary


1 Answers

move_uploaded_file() is a php function, running on a PHP-based server-side application.

It is handled by PHP when your form has been submitted.

You cannot access it from JavaScript before it has been sent, whatever would be the way you would submit it, both asynchronously with an XHR Request, or directly submitting the form to its handler route.

like image 196
Flo Schild Avatar answered Oct 20 '22 01:10

Flo Schild