Define initial directory in input type File?

0

Is it possible to define the initial folder that is displayed when clicking on a component <input type="file"> ??, that is, I place the label:

<input id="fileupload" type="file" name="files[]" accept=".png" multiple required/>

and this executes the file explorer well, but let's say, I need that instead of opening it in the desktop (that's how it opens by default) open me in My Documents.

How could I do this?

Additionally, if someone knows how to eliminate the Todos los archivos option that appears in the filter, and only the option or options that I chose in accept

appear     
asked by Fabian Montoya 23.02.2017 в 21:43
source

1 answer

2

To filter by file type, in this case PNG, you should put content-type , in this case image/png :

<input id="fileupload" type="file" name="files[]" accept=".png,image/png" multiple required/>

Anyway, that filter is only for the user's convenience. He himself can change the filter to see all the files, and then upload anything. Even if you could force him to maintain that filter, he could rename any file and upload it. This means that if you really want to receive only PNG, you will have to detect the MIME type on the server side.

Respect to force the folder where the dialog opens, that is not possible with HTML. First it is impractical, the absolute path of anything depends on the operating system. Second, it would be a security risk for anyone who operated with such a form.

    
answered by 23.02.2017 в 23:04