upload.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. $target_dir = "uploads/";
  3. if (isset($_GET['VB_upload']) && $_GET['VB_upload'] == "true"){
  4. $target_file = $target_dir . basename($_FILES["file"]["name"]);
  5. $_FILES["fileToUpload"] = $_FILES["file"];
  6. }else{
  7. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  8. }
  9. $uploadOk = 1;
  10. $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
  11. $filename = "";
  12. $displayMsg = "";
  13. $jsonReply = false;
  14. //Check if it is a program request or not
  15. if (isset($_GET['json']) && $_GET['json'] == "true"){
  16. $jsonReply = true;
  17. }
  18. // Check if file already exists
  19. if (file_exists($target_file)) {
  20. //echo "Sorry, file already exists.";
  21. $uploadOk = 0;
  22. $displayMsg = "Upload Failed: File already exists";
  23. }
  24. // Check file size
  25. if ($_FILES["fileToUpload"]["size"] > 25000000) {
  26. //echo "Sorry, your file is too large.";
  27. $uploadOk = 0;
  28. $displayMsg = "Upload Failed: File larger than 25MB";
  29. }
  30. // Allow certain file formats
  31. if($imageFileType == "php") {
  32. $uploadOk = 0;
  33. }
  34. // Check if $uploadOk is set to 0 by an error
  35. if ($uploadOk == 0) {
  36. //echo "Sorry, your file was not uploaded.";
  37. // if everything is ok, try to upload file
  38. //$displayMsg = "Sorry, your file was not uploaded. (Maybe file already exists / Not allowed format / file larger than 25MB)";
  39. } else {
  40. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  41. //echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  42. $filename = $_FILES["fileToUpload"]["name"];
  43. $displayMsg = "Upload Succeed";
  44. } else {
  45. $displayMsg = "Upload Failed: Internal Server Error";
  46. //echo "Sorry, there was an error uploading your file.";
  47. }
  48. }
  49. if ($filename != ""){
  50. //DONE
  51. $memodir = "Memo/";
  52. $content = "data:file/" . $filename;
  53. $content = bin2hex($content);
  54. $max = 0;
  55. foreach (new DirectoryIterator($memodir) as $fileInfo) {
  56. if ($fileInfo->isDot()) continue;
  57. $current = pathinfo($fileInfo->getFilename())['filename'];
  58. if (!is_numeric($current)) continue;
  59. if ($current > $max) $max = $current;
  60. }
  61. //Check if the number of files exceed the max
  62. if ($max > 1000){
  63. foreach (new DirectoryIterator($memodir) as $fileInfo) {
  64. $current = pathinfo($fileInfo->getFilename())['filename'];
  65. if (!is_numeric($current)) continue;
  66. if ((int)$current != 0){
  67. unlink($memodir . $current . ".txt");
  68. }
  69. }
  70. $max = 0;
  71. }
  72. $filename = (int)$max + 1;
  73. $myfile = fopen($memodir . $filename . ".txt", "w") or die("Unable to open file!");
  74. $txt = $content;
  75. fwrite($myfile, $txt);
  76. fclose($myfile);
  77. //echo $filename;
  78. if ($jsonReply == true){
  79. if ($uploadOk == 0){
  80. header('Content-Type: application/json');
  81. echo json_encode(-1);
  82. }else{
  83. header('Content-Type: application/json');
  84. echo json_encode($filename);
  85. }
  86. exit();
  87. }
  88. }else{
  89. if ($jsonReply == true){
  90. if ($uploadOk == 0){
  91. echo json_encode("Upload Failed: File already exists / Not allowed format / file larger than 25MB");
  92. }
  93. exit();
  94. }
  95. }
  96. ?>
  97. <html>
  98. <meta name="viewport" content="width=device-width, initial-scale=1">
  99. <head>
  100. <title>Quick Send</title>
  101. <link rel="stylesheet" href="tocas.css">
  102. </head>
  103. <body>
  104. <?php
  105. if (isset($_GET['rx']) && $_GET['rx'] != ""){
  106. header("Location: display.php?id=" . $_GET['rx']);
  107. die();
  108. }
  109. ?>
  110. <div class="ts inverted heading fluid slate" style="background-color:#2c2835;color:white;">
  111. <span class="large header">Quick Send System</span>
  112. <span class="description">Send data between mobile and laptops.<br> Powered by IMUS Laboratory</span>
  113. <div class="ts bottom attached tabbed menu" style="color:white;">
  114. <a class="item" href="index.php" style="color:#9d9ca3;">Text</a>
  115. <a class="active item" href="file.php">Files</a>
  116. <a class="item" href="rx.php" style="color:#9d9ca3;">Receive</a>
  117. <!-- <a class="item" href="img.php" style="color:#9d9ca3;">Image</a> -->
  118. </div>
  119. </div>
  120. <div class="ts container">
  121. <br><br>
  122. <div class="ts stackable grid">
  123. <div class="four wide column" align="center">
  124. <div id="output"></div>
  125. <div class="ts small statistic">
  126. <div class="label">QuickSend ID</div>
  127. <div class="value" id="sid"><?php
  128. $max = 0;
  129. foreach (new DirectoryIterator('Memo/') as $fileInfo) {
  130. if ($fileInfo->isDot()) continue;
  131. $current = pathinfo($fileInfo->getFilename())['filename'];
  132. if (!is_numeric($current)) continue;
  133. if ($current > $max) $max = $current;
  134. }
  135. echo $max;
  136. ?></div>
  137. </div>
  138. </div>
  139. <div class="center aligned twelve wide column">
  140. <p class="ts header"><?php echo $displayMsg;?></p><br>
  141. <a href="file.php" class="ts basic button">Upload Next File</a>
  142. <br>
  143. </div>
  144. </div>
  145. <br><br><br><br><br><br>
  146. <div style="position: fixed;
  147. z-index: 100;
  148. bottom: 0;
  149. left: 0;
  150. width: 100%;
  151. background-color:#2c2835;
  152. color:white;">
  153. <div class="ts container">
  154. <img class="ts tiny right floated image" src="img/cube.png"></img>
  155. </div>
  156. <div align="left" class="ts container">
  157. <br>
  158. CopyRight IMUS Laboratory 2021, All right reserved.
  159. </div>
  160. </div>
  161. </div>
  162. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
  163. <script type="text/javascript" src="jquery.qrcode.min.js"></script>
  164. <script>
  165. var data = <?php echo $max;?>;
  166. jQuery(function(){
  167. jQuery('#output').qrcode("http://imuslab.com/qs/display.php?id=" + data);
  168. })
  169. </script>
  170. </body>
  171. </html>