Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
as i am new to php can get proper code to run batch file for button click event
using php code.

What I have tried:

Codes I have tried
1)
<button id="myButton">Click Me</button>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $('#myButton').click(function(){
        $.ajax({
            url: "C:/Users/Downloads/Desktop/HelloWorld.bat",
            type: "POST",
            success: function(response){
                // Handle the response from the server
                console.log(response);
            }
        });
    });
});
</script>  


2)
<a href="C:/Users/Downloads/Desktop/HelloWorld.bat">
    open batch file_name
</a>
Posted
Updated 29-Jun-23 3:43am

You can't.
PHP code runs on the server, not the client - and for understandable security reasons you cannot run any application on the client from server code, or even directly access the client file system.

You can run apps on the server, but the client will never be able to see any results (if the hosting service allows it and the file is accessible to the user ID that the hosting software is running under - which is normally very restricted in what it can access, again for security reasons!)
 
Share this answer
 
You cannot run anything on the client machine from a web page, be it generated by your PHP code, or javascript in your page, or using an HTML "A" tag.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900