upgrade_iso.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. ini_set('error_reporting', E_ALL | E_STRICT);
  3. $tag_header = 'upgrade';
  4. include 'head.php';
  5. ?>
  6. <style>
  7. img {
  8. display: block;
  9. margin-left: auto;
  10. margin-right: auto;
  11. }
  12. </style>
  13. <div class="envor-content">
  14. <!--
  15. Page Title start
  16. //-->
  17. <section class="envor-page-title-1" data-stellar-background-ratio="0.5">
  18. <div class="container">
  19. <div class="row">
  20. <div class="col-lg-9 col-md-9 col-sm-9">
  21. <h1><?php echo $lang->showWord("upgrade"); ?></h1>
  22. </div>
  23. </div>
  24. </div>
  25. <!--
  26. Page Title end
  27. //-->
  28. </section>
  29. <!--
  30. Main Content start
  31. //-->
  32. <a id="loadinghref"><div id="loading" style="display:none;"><img src="img/giphy.gif"/></div></a>
  33. <section class="envor-section">
  34. <div class="container">
  35. <div class="row">
  36. <div class="col-lg-12">
  37. <h2>Image <?php echo $lang->showWord("upgrade");?></h2>
  38. <div class="file-loading">
  39. <input name="file_iso" id="file_iso" type="file" class="file" data-show-preview="false" data-show-upload="false" <?php //data-allowed-file-extensions='["iso"]' ?>>
  40. </div>
  41. <?php /* <input type="submit" class="btn btn-primary" id="upload_iso"></button>
  42. <input type="reset" class="btn btn-outline-secondary"></button>*/?>
  43. <article class="envor-sorting-item css">
  44. <div align="center"><button id="upload_iso"><?php echo $lang->showWord("set")?></button></div>
  45. </article>
  46. </div>
  47. <div class="col-lg-12">
  48. <h2><?php echo $lang->showWord("upgrade_status");?></h2>
  49. <!-- <textarea id="description" rows="2" class="form-control" placeholder=""></textarea>-->
  50. <p id="createResult"></p>
  51. </div>
  52. </div>
  53. </div>
  54. <!--
  55. Main Content start
  56. //-->
  57. </section>
  58. </div>
  59. <?php
  60. include 'foot.php';
  61. ?>
  62. <script type="text/JavaScript">
  63. document.getElementById("upload_iso").onclick = function() {
  64. if(formCheck("iso"))
  65. {
  66. window.location="#loadinghref";
  67. document.getElementById("loading").style.display="block";
  68. var fileInput = document.getElementById('file_iso');
  69. // 發送 Ajax 查詢請求並處理
  70. var request = new XMLHttpRequest();
  71. request.open("POST", "upgrade_iso_action.php");
  72. // POST 參數須使用 send() 發送
  73. var formData = new FormData();
  74. //var formData = new FormData(document.getElementById("file_iso"));
  75. var file = fileInput.files[0];
  76. formData.append("fw_tag", "iso");
  77. formData.append("file", file);
  78. // POST 請求必須設置表頭在 open() 下面,send() 上面
  79. request.upload.onprogress = function(e) {
  80. document.getElementById("createResult").innerHTML = "Upload " + (Math.round( (e.loaded/e.total) *10000)/100) + "%";
  81. }
  82. request.send(formData);
  83. request.onreadystatechange = function() {
  84. // 伺服器請求完成
  85. if (request.readyState == 4) {
  86. document.getElementById("loading").style.display="none";
  87. // 伺服器回應成功
  88. if (request.status == 200) {
  89. document.getElementById("createResult").innerHTML = "";
  90. document.getElementById("createResult").innerHTML = request.responseText;
  91. //location.href="upgrade_iso.php";
  92. } else {
  93. alert(JSON.parse(request.responseText).message);
  94. }
  95. request = null;
  96. }
  97. else{
  98. document.getElementById("createResult").innerHTML = request.responseText;
  99. }
  100. }
  101. }
  102. }
  103. function formCheck(fw_tag)
  104. {
  105. var file_type;
  106. if(fw_tag=="iso")
  107. {
  108. if(document.getElementById("file_iso").value.substring(document.getElementById("file_iso").value.length-3) != "hex")
  109. {
  110. // alert("Firmware file type is wrong, please check file type.(*.hex)");
  111. // document.getElementById("file_iso").focus();
  112. // return false;
  113. }
  114. if(document.getElementById("file_iso").value.length <= 0)
  115. {
  116. alert("Firmware is not select, please check!");
  117. document.getElementById("file_iso").focus();
  118. return false;
  119. }
  120. // if(confirm("Are you sure to update AC MCU firmware file now?...") == 1 )
  121. return true;
  122. // else
  123. // return false;
  124. }
  125. else
  126. return false;
  127. }
  128. function isNumberKey(evt)
  129. {
  130. var charCode = (evt.which) ? evt.which : event.keyCode
  131. if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
  132. return false;
  133. return true;
  134. }
  135. </script>