get_button_action.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. // 設置資料類型 json,編碼格式 utf-8
  3. header('Content-Type: application/json; charset=UTF-8');
  4. // 判斷如果是 GET 請求,則進行搜尋;如果是 POST 請求,則進行新建
  5. // $_SERVER['REQUEST_METHOD'] 返回訪問頁面使用的請求方法
  6. if ($_SERVER['REQUEST_METHOD'] == "GET") {
  7. create();
  8. } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
  9. create();
  10. }
  11. // 新建員工
  12. function create() {
  13. chdir("/root");
  14. exec("'./WebService' 'button'",$output,$return_var);
  15. if(count($output)==0){
  16. // echo '<script>alert("Something went wrong on machine");</script>';
  17. echo "Something went wrong on machine";
  18. exit;
  19. }
  20. if(trim($output[0])=="InitShareMemory Error"){
  21. // echo '<script>alert("InitShareMemory Error");</script>';
  22. echo "InitShareMemory Error";
  23. exit;
  24. }
  25. $obj[1] = trim($output[0]);
  26. $obj[2] = trim($output[1]);
  27. $obj[3] = trim($output[2]);
  28. $obj[4] = trim($output[3]);
  29. $obj10 = json_decode(trim($output[0]));
  30. $obj20 = json_decode(trim($output[1]));
  31. $obj30 = json_decode(trim($output[2]));
  32. $obj40 = json_decode(trim($output[3]));
  33. $arr=array($obj10,$obj20,$obj30,$obj40);
  34. $obj[0]=json_encode($arr);
  35. echo $obj[$_REQUEST['opt']];
  36. }
  37. ?>