upgrade_iso_action.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. include 'lang.php';
  14. $lang = new Lang;
  15. $lang->getLang();
  16. $message = $lang->showWord("message_upgrade");
  17. chdir('/root');
  18. echo '<font color=#ff0000>Work directory: '.getcwd().'<br>';
  19. echo 'System date/time: '.nl2br(shell_exec('date +%Y-%m-%d_%H:%M:%S')).'</font>';
  20. // ini_set('max_execution_time','120');
  21. // ini_set('max_input_time','120');
  22. // ini_set('post_max_size','2048M');
  23. // ini_set('upload_max_filesize','2048M');
  24. if($_POST['fw_tag']=='iso')
  25. {
  26. if ($_FILES["file"]["error"] > 0)
  27. {
  28. echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  29. }
  30. else
  31. {
  32. echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  33. echo "Type: " . $_FILES["file"]["type"] . "<br />";
  34. echo "Size: " . ($_FILES["file"]["size"]) . " <br />";
  35. echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
  36. echo "<font color=#000fff>Upgrade is completed</font><br />";
  37. }
  38. //ob_start();
  39. sleep(1);
  40. move_uploaded_file($_FILES["file"]["tmp_name"],"/mnt/".$_FILES["file"]["name"]);
  41. chdir("/root");
  42. $str_json=json_encode($json);
  43. exec("'./WebService' 'upgrade' '".$_FILES["file"]["name"]."'",$output,$return_var);
  44. echo 'Result:'.json_decode(trim($output[0]))->{'Result'}.' Message:'.json_decode(trim($output[0]))->{'Message'};
  45. //printf($output);
  46. // move_uploaded_file($_FILES["file"]["tmp_name"],"/tmp/".'csu.iso');
  47. //shell_exec('sudo mv /tmp/csu.iso /var/www/html/csu.iso');
  48. //system('echo "y42j/4cj84" | sudo mv /tmp/csu.iso /var/www/html/csu.iso');
  49. // shell_exec('mv /tmp/csu.iso /var/www/html/csu.iso');
  50. // $json = json_decode(file_get_contents("localUpdate"), true);
  51. // $json['mcu'] = 1;
  52. // file_put_contents("./localUpdate", json_encode($json));
  53. //while (@ ob_end_flush()); // end all output buffers if any
  54. // $proc = popen('sudo /root/restart_charger.sh', 'r');
  55. // echo '<pre>';
  56. // while (!feof($proc))
  57. // {
  58. // echo fread($proc, 512);
  59. // @ flush();
  60. // }
  61. // echo '</pre>';
  62. //ob_end_clean();
  63. //echo "<font color=#000fff>Upgrade is completed</font>";
  64. }
  65. shell_exec('sync;sync;sync');
  66. }
  67. ?>