run program or command using php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nugroho
    New Member
    • Jul 2007
    • 4

    #1

    run program or command using php

    i want to run a unix/linux program with a php script.
    i have two textbox named text1 and text2
    and one button named execute.
    if the button clicked then execute a unix command
    like this :
    execute( "cp text1 text2")

    "cp" is unix command for copy
    "text1" is directory source file to copy
    "text2" is destination directory

    how's the code looks like, write me an example.
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Create a form. Check this link to how form works if you dont know http://www.w3schools.c om/php/php_forms.asp.

    On receiving submitted data, use exec() to run the commands

    <?
    $text1 = escapeshellcmd( $_POST["text1"]);
    $text2 = escapeshellcmd( $_POST["text2"]);
    exec("cp $text1 $text2")
    ?>

    Use escapeshellcmd( ) to avoid any problems.

    Comment

    • nugroho
      New Member
      • Jul 2007
      • 4

      #3
      Originally posted by mwasif
      Create a form. Check this link to how form works if you dont know http://www.w3schools.c om/php/php_forms.asp.

      On receiving submitted data, use exec() to run the commands

      <?
      $text1 = escapeshellcmd( $_POST["text1"]);
      $text2 = escapeshellcmd( $_POST["text2"]);
      exec("cp $text1 $text2")
      ?>

      Use escapeshellcmd( ) to avoid any problems.
      thanks, i've follow that procedur, but nothings happen
      here is my work

      filename = fm_utdes.html
      Code:
      <html>
      
      <head>
      
      <title>Form1 </title>
      
      
      
      </head>
      
      <body>
      
      <form action="fm_prodes.php" method="post">
      
        <table width="350"  border="0" align="center" cellpadding="4" cellspacing="0" class="keliling">
      
          <tr align="left">
      
            <th colspan="2" scope="col"><div align="center">Form1</div></th>
      
          </tr>
      
          <tr>
      
            <td width="35%">Source file </td>
      
            <td>:      
      
            <input name="txt1" type="text" size="27" maxlength="50"></td>
      
          </tr>
      
      	<tr>
      
            <td width="35%">final file </td>
      
            <td>:      
      
            <input name="txt2" type="text" size="27" maxlength="50"></td>
      
          </tr>
      
      	 <tr>
      
            <td>&nbsp;</td>
      
            <td><input type="submit">
      
            
      
          </tr>
      
        </table>
      
      </form>
      
      </body>
      
      </html>
      and, this is for submit
      filename = fm_prodes.php
      Code:
      <?php
                      $text1 = escapeshellcmd($_POST["txt1"]);
      		$text2 = escapeshellcmd($_POST["txt2"]);
      		exec("cp $text1 $text2");
      ?>

      Comment

      Working...