upload.php 5.2 KB

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