How to send a file from local disk using document get element

I have a input box, which i want to replace directly by sending a file from local disk or folder.
var fileInput = document.createElement(“input”);
This above line where we get input from user. But i want to replace it with file path and follows next step. How to pass a local directory file path to fileInput.
I don want any button to accept from user. I should be directly passing file path. Please help me

Due to security reasons you cannot pre-define the file to upload. The file to upload must always be selected by the user.

1 Like

I m getting input from user in another page, that input i want to send here… so can i get that itself??

No, you can’t use values from elsewhere, as these values are not secure with regards to the required security level.

If you’ve already gotten the file’s contents from an upload in another page, at that point you’re not trying to access the information on the user’s PC, and should be referring to the information that was uploaded to your backend by the previous page.

You cannot take a text input of a file path and access a file on the user’s PC. Period.

Can we create a input id and get the required file but run in backend or like hiding it.

A file input requires the user to click on the item and select a file to upload. You cannot ‘hide’ this, it is a thing that must be manipulated by the user.

There is no way in Javascript to ‘get the required file’ from a user’s computer without the user being the one to select the file and upload it.

If there were, when you visit my website, I could tell your PC to send me your password file. Would you like that?

then the only solution is to keep a button and accept user file?

yes.

we cant keep input button hidden and send a input from html to js?

If the input button is hidden, how does the user push it to select the file to upload?

that can we automate from previous page?? sorry if im wrong

“Previous page”… you keep saying that, but look…

If the previous page has a file upload on it, and the user pushes ‘go’… then the file gets submitted to your server’s form handler. At that point, the data is in your server - you dont need to access the user’s PC anymore, you’ve already got the data. Your server’s form handler can spit the data back into the next page’s javascript, if needs be.

If you wanted to do something with the form’s data immediately in Javascript, you’d do it back on that previous page… the one with the file upload input. Which… defeats the entire purpose of the page you’re describing now.

thank u sir…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.