简体   繁体   中英

Executing a .sh file with php

I have written a very simple Hello World script as a bash file and saved it on my desktop.

I want to execute this file when a Submit button is pressed.

The following script works fine and I see the Hello World on the firefox webbrowser:

   <?php

     echo shell_exec('sh /home/administrator/Desktop/Helloworld.sh');

    ?>

However the following script does not give me any result:

<!DOCTYPE html>
  <html>

<body>

<?php
if (isset($_POST['Submit1'])) {

 echo shell_exec('sh /home/administrator/Desktop/Helloworld.sh');
  }

 ?>

<Input Type = "Submit" Name ="Submit1" Value = "Save Parameters">


</body>
</html>

Any idea why? I don't get any errors in my log file.

You are not posting anything, for that you'll need a form, ie:

file.php

<html>
<body>
<?php
if (isset($_POST['Submit1'])) {
 echo shell_exec('sh /home/administrator/Desktop/Helloworld.sh');
  }
 ?>
<form action="file.php" method="post">
<input Name= "Submit1" type="submit">
</form>

</body>
</html>

Also, make sure the file /home/administrator/Desktop/Helloworld.sh is executable, ie:

chmod +x /home/administrator/Desktop/Helloworld.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM