<input> to select files/folders automatically - javascript

I am using javascript and html to load a file (browser).
I currently have this:
<input type="file" id="file-input" #input="openFile" />
Then openFile() loads the file using the FileReader API.
My question is, since actually, I want the file to load dynamically - I do not want to have a user prompt for file input. Any way to achieve this? How about for directories (recursively get all matching files and open/display the files in the browser)?
The files I need to load are xml data files and will be parsed for displaying purposes.
These files are located locally (as part of the web page bundle). This web page will be loaded locally - no servers/local serveres whatsoever.
Help please!
Thanks!

It is not possible because of security policies. File input cannot choose element, it allow scammers to steal files from user's computer.

Related

Opening .odt files on webpage using html

I'm currently working on web page and trying to open .odt files by using html and javascript. The .odt files are stored in my computer and I want to print them in my web page. Plus, is it possible to store each sentences(which are in .odt file) in variables one by one? My goal is to open .odt file on web page, modify the contents of .odt file, and then save the .odt file back to my computer.
sorry that my question is abstract but I just started. There's not much related information on google please help 😥

Is it possible to save a local file to a different location in the same computer using javascript?

I have a file named file.pdf in my root directory along with my index.html page, Is there any way I can open a file dialogue manager using <input id="savefile" type="file"> and save file.pdf in a different location on the same system. I know that modern browsers will not give the full path due to security issue. Is there a way to do this with JavaScript and html?
You cannot do that.
JavaScript runs on client side and it’s scope doesn't allows you to modify any files directly.

Is it possible to get access permission for a folder in local file system from browser

I want to make a local file editor. To open some files edit them and save them back. It's ok if it only works in Chrome. Using
<input type="file" id="filepicker" name="fileList" webkitdirectory multiple />
I can read all the files and draw the file tree but I want to also be able to edit and save to these files. Even create new files and folders.
Is there any way to do it. I'm also ok with hacks that use Java or Flash or simply any other hack if HTML5 does not offer any solution.
Thanks
I do not believe what you are suggesting is possible; however, there is a different approach that should solve your problem.
If you take Microsoft's Online Word for example... They have it setup so you save document to the cloud and then can edit them with an online copy of Microsoft Word.
In otherwords, the user would upload a file. Your server would then take the file, display it and allow the user to edit the file. The user would then save the changes to the file. You can then provide an option to re-download the file.
To more closely emulate editing a file on the local file system, you can also setup a "temporarily" save on the server.
Essentially, the user uploads a file. The server would allow the user to view and edit the file. When the user wishes to save it, instead of saving the file on the server, give it back as a download to the user.
After the user leaves your site you can delete the copy of the file that is saved on your server.

search local directory using html file api and javascript

I am planning to create an app using html5 file api and javascript to take directory path as input and be able to process (search for a text) all files in that directory and sub directories.
currently I am doing it using batchscript, What are constraints/obstacles doing it using HTML/javascript.
In short: You can't to that automatically.
Access the local filesystem from any browser is blocked for security reasons. Reason: Imagine any website being able to access the files on your filesystem.
Read this: Local file access with javascript
Maybe you want to rephrase your question and say what you actually want to acheive.
You can access simple file information using the user's input and using <input type=file>. But the user would require to do the following steps:
Click the "Browse button" (a file dialogue appears).
Navigate to the requested folder.
Select 1 or many files.
Click "Open".
Mozilla has documented this well with an example: https://developer.mozilla.org/en/docs/Using_files_from_web_applications#Example_Showing_file(s)_size

Find the path of a local file or directory in javascript

We are building a web application to help people organize their local files; it has a text input field in HTML5/JS.
Ideal functionality: user clicks on the text box and it lets them select a file or folder on their local drive, which passes the path of said file or folder to our server.
Is there a JS API or HTML5 method to find a path to a local file and folder?
Due to browser security, you cannot get the file location from a FILE input. For that same reason, you will notice that FILE inputs always get reset to blank after a postback. This is because the browser will not persist or expose the file path as a security measure.

Categories