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 the button for sending is clicked, the JavaScript function is executed (url: upload.php). I need to have access to $_FILES["inputID"]["tmp_name"] from this input field so that I can use it on upload.php as,

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

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

Note: Undefined index: inputID

Any help would be greatly appreciated.

Thank you very much!: -)

+6
source share
2 answers

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

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

You cannot access it with JavaScript before sending it, no matter how you sent it, asynchronously with the XHR request, or directly submitting the form to your handler route.

+3
source

you can access it after sending it, although I do not understand why you should:

 <?php ... $tmpname=$_FILES["file"]["tmp_name"] ... ?> ... <script> var tmpname = <?=$tmpname?> ... </script> ... 

I do not understand what you are trying to do. If you need some kind of ajax download function, it is better to use the js library.

0
source

All Articles