0

Actually I need to check the file or image that is already existed or not in our local c or d drive. how do I achieve it.?

here is my code.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
 
    function checkIfFileLoaded(fileName) {
    $.get(fileName, function(data, textStatus) {
        if (textStatus == "success") {
            // execute a success code
            console.log("file loaded!");
        }
    });
}

    $("p").click(function(){
        checkIfFileLoaded("C:\\Vignesh Mohanraj\\vignesh.txt");
    });
    
    
});
</script>
</head>
<body>

<p>click for check</p>


</body>
</html>

Please help me to solve this.

Vignesh Mohanraj
  • 159
  • 1
  • 2
  • 13

1 Answers1

1

You can't because of browser cross origin policy.

You'll get this error.

Failed to load file:///C:/Vignesh Mohanraj/vignesh.txt: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

Learn more about it here "Cross origin requests are only supported for HTTP." error when loading a local file