在jquery中获取fakepath

am trying get size of a file by passing the file bath from javascript to an php file then return the result , problem is javascript passing file bath as the following ex, c:\fakepath\NAME OF THE FILE , so the php file getting an wrong path so always returning an false !!!

 $(document).ready(function (){


        $("#file").click(function (){


            fileBath=$("#name").val();

                $.get('newfile2.php','fileBath='+fileBath,function(data){
                alert(data);

                    });
            });
});

php file

getmax($_GET['fileBath']);

function getmax($fileBath){

    $value=filesize($fileBath);
    echo  $value;

}

as i said the return value FALSE in php file because file bath is wrong !!

use php str_replace or preg_replace .it will replace the unnecessary space or whatever you want then there wont be any problem

The purpose of the file input is to allow a file to be uploaded. The structure of the visitor's file system is considered to be confidential information that websites should not need.

There is no way to bypass the fakepath substitution as it is there to protect the visitor's privacy.

since arising of HTML5 browsers implement strict rules to protect user's privacy, and the fakepath is used to hide the real path of the file, even on the MAC the path is C:\\fakepath..

so you can only detect the name of the file not it's real path, try this::

var filename = $('#name').val().replace(/C:\\fakepath\\/i, '');

JavaScript solution:

document.getElementById("fileInput").files[0].name;

jQuery solution:

$("#fileInput")[0].files[0].name;