'get folder directory from input type file - PHP

just a quick question,

mission is to get a folder directory name. example: _C:\ThisFolder\myFolder_.

and I've used html input type="file" but I'm only able to get the file name, plus type="file" works like one want to upload something, while I just want to get the folder path of user selection.

<label> Update to  : </label>
<input type="file" class="form-control" id="dirpath" name="dirpath" directory />

is there any other approach that I could use, please advice, thanks.



Solution 1:[1]

Due to security reasons browser does not allow it. Browser has no access to the file system. If you need the file's path for reading a file you can use the FileReader API instead.

Solution 2:[2]

Try this code,

   
    	$('#dirpath').on('change',function ()
            {
                var filePath = $(this).val();
                console.log(filePath);
            });
<label> Update to  : </label>
    <input type="file" class="form-control" id="dirpath" onchange="fileget(event)" name="dirpath" directory />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

Solution 3:[3]

Maybe you can just use it like this:

<label> Update to  : </label>
<input type="file" class="form-control" id="dirpath" name="dirpath" directory onSubmit = getPath()/>

<script language="javascript" type="text/javascript">
function getPath() {
     var inputName = document.getElementById('dirname');
     var Path;

     Path = inputName.value;
}
</script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Praveen Gupta
Solution 2
Solution 3 Serafin William