Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open specific folder in <input type='file'>

I want to upload images in my project from specific folder. when i click on choose file button it goes to default folder or last opened folder but i want to do it always open some specific folder like documents/all images/animals images/.

 <table>  
            <tr>  
                <td>First Name:</td>    
                <td><input type="text" name="firstName" size="10"  
                    required="required" /></td>  
            </tr>  
            <tr>  
                <td>Last Name:</td>  
                <td><input type="text" name="lastName" size="10"  
                    required="required" /></td>  
            </tr>  
            <tr>  
                <td>Choose Image:</td>  
                <td><input type="file" name="photo" size="10"  
                    required="required" /></td>  
            </tr>  
            <tr>  
                <td><input type="submit" value="Submit"></td>  
                <td><input type="reset" value="Clear" /></td>  
            </tr>  
        </table> 

someone tell me solution for this.

like image 350
MMMMS Avatar asked Sep 03 '15 06:09

MMMMS


People also ask

How do I select a file in a directory in HTML?

The <input type="file"> defines a file-select field and a "Browse" button for file uploads. To define a file-select field that allows multiple files to be selected, add the multiple attribute. Tip: Always add the <label> tag for best accessibility practices!

What is Webkitdirectory?

webkitdirectory is a property that reflects the webkitdirectory HTML attribute and indicates that the <input> element should let the user select directories instead of files. When a directory is selected, the directory and its entire hierarchy of contents are included in the set of selected items.

How can I get full path of uploaded file in HTML using jquery?

var fullPath = $('#fileUpload1'). val();


2 Answers

Actually that's impossible because of security reason with a pure HTML / Javascript. I don't if it's possible if you use ActiveX or Java Applet but those technologies are outdated.

like image 146
Stephanus Budiwijaya Avatar answered Oct 17 '22 00:10

Stephanus Budiwijaya


Now you can do that, but only if you're using "Chrome" which supports these last two attributes:

<input type="file" id="folder-opener" webkitdirectory multiple/>

This worked well for me, though keep in mind that now this input tag won't let you select single files. Just directories.

If that's ok for you, then you'll be able to list all files in the selected directory on the back-end side by passing the absolute path:

document.getElementById('folder-opener').addEventListener('change', function(event) {
  // Selected folder's absolute path:
  console.log(event.target.files[0].path);
});
like image 41
Ustym Ukhman Avatar answered Oct 16 '22 23:10

Ustym Ukhman