123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- $target_dir = "uploads/";
- if (isset($_GET['VB_upload']) && $_GET['VB_upload'] == "true"){
- $target_file = $target_dir . basename($_FILES["file"]["name"]);
- $_FILES["fileToUpload"] = $_FILES["file"];
- }else{
- $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
- }
- $uploadOk = 1;
- $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
- $filename = "";
- $displayMsg = "";
- $jsonReply = false;
- //Check if it is a program request or not
- if (isset($_GET['json']) && $_GET['json'] == "true"){
- $jsonReply = true;
- }
- // Check if file already exists
- if (file_exists($target_file)) {
- //echo "Sorry, file already exists.";
- $uploadOk = 0;
- $displayMsg = "Upload Failed: File already exists";
- }
- // Check file size
- if ($_FILES["fileToUpload"]["size"] > 25000000) {
- //echo "Sorry, your file is too large.";
- $uploadOk = 0;
- $displayMsg = "Upload Failed: File larger than 25MB";
- }
- // Allow certain file formats
- if($imageFileType == "php") {
- $uploadOk = 0;
- }
- // Check if $uploadOk is set to 0 by an error
- if ($uploadOk == 0) {
- //echo "Sorry, your file was not uploaded.";
- // if everything is ok, try to upload file
- //$displayMsg = "Sorry, your file was not uploaded. (Maybe file already exists / Not allowed format / file larger than 25MB)";
- } else {
- if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
- //echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
- $filename = $_FILES["fileToUpload"]["name"];
- $displayMsg = "Upload Succeed";
- } else {
- $displayMsg = "Upload Failed: Internal Server Error";
- //echo "Sorry, there was an error uploading your file.";
- }
- }
- if ($filename != ""){
- //DONE
- $memodir = "Memo/";
- $content = "data:file/" . $filename;
- $content = bin2hex($content);
- $max = 0;
- foreach (new DirectoryIterator($memodir) as $fileInfo) {
- if ($fileInfo->isDot()) continue;
- $current = pathinfo($fileInfo->getFilename())['filename'];
- if (!is_numeric($current)) continue;
- if ($current > $max) $max = $current;
- }
-
- //Check if the number of files exceed the max
- if ($max > 1000){
- foreach (new DirectoryIterator($memodir) as $fileInfo) {
- $current = pathinfo($fileInfo->getFilename())['filename'];
- if (!is_numeric($current)) continue;
- if ((int)$current != 0){
- unlink($memodir . $current . ".txt");
- }
- }
- $max = 0;
- }
-
- $filename = (int)$max + 1;
- $myfile = fopen($memodir . $filename . ".txt", "w") or die("Unable to open file!");
- $txt = $content;
- fwrite($myfile, $txt);
- fclose($myfile);
- //echo $filename;
-
- if ($jsonReply == true){
- if ($uploadOk == 0){
- header('Content-Type: application/json');
- echo json_encode(-1);
- }else{
- header('Content-Type: application/json');
- echo json_encode($filename);
- }
- exit();
- }
- }else{
- if ($jsonReply == true){
- if ($uploadOk == 0){
- echo json_encode("Upload Failed: File already exists / Not allowed format / file larger than 25MB");
- }
- exit();
- }
- }
- ?>
- <html>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <head>
- <title>Quick Send</title>
- <link rel="stylesheet" href="tocas.css">
- </head>
- <body>
- <?php
- if (isset($_GET['rx']) && $_GET['rx'] != ""){
- header("Location: display.php?id=" . $_GET['rx']);
- die();
- }
- ?>
- <div class="ts inverted heading fluid slate" style="background-color:#2c2835;color:white;">
- <span class="large header">Quick Send System</span>
- <span class="description">Send data between mobile and laptops.<br> Powered by IMUS Laboratory</span>
- <div class="ts bottom attached tabbed menu" style="color:white;">
- <a class="item" href="index.php" style="color:#9d9ca3;">Text</a>
- <a class="active item" href="file.php">Files</a>
- <a class="item" href="rx.php" style="color:#9d9ca3;">Receive</a>
- <!-- <a class="item" href="img.php" style="color:#9d9ca3;">Image</a> -->
- </div>
- </div>
- <div class="ts container">
- <br><br>
- <div class="ts stackable grid">
- <div class="four wide column" align="center">
- <div id="output"></div>
- <div class="ts small statistic">
- <div class="label">QuickSend ID</div>
- <div class="value" id="sid"><?php
- $max = 0;
- foreach (new DirectoryIterator('Memo/') as $fileInfo) {
- if ($fileInfo->isDot()) continue;
- $current = pathinfo($fileInfo->getFilename())['filename'];
- if (!is_numeric($current)) continue;
- if ($current > $max) $max = $current;
- }
- echo $max;
- ?></div>
- </div>
- </div>
- <div class="center aligned twelve wide column">
- <p class="ts header"><?php echo $displayMsg;?></p><br>
- <a href="file.php" class="ts basic button">Upload Next File</a>
- <br>
- </div>
- </div>
- <br><br><br><br><br><br>
- <div style="position: fixed;
- z-index: 100;
- bottom: 0;
- left: 0;
- width: 100%;
- background-color:#2c2835;
- color:white;">
- <div class="ts container">
- <img class="ts tiny right floated image" src="img/cube.png"></img>
- </div>
- <div align="left" class="ts container">
- <br>
- CopyRight IMUS Laboratory 2021, All right reserved.
- </div>
- </div>
- </div>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
- <script type="text/javascript" src="jquery.qrcode.min.js"></script>
- <script>
- var data = <?php echo $max;?>;
- jQuery(function(){
- jQuery('#output').qrcode("http://imuslab.com/qs/display.php?id=" + data);
- })
- </script>
- </body>
- </html>
|