index.php (2769B)
1 <?php 2 /* 3 Copyright (C) <2022> <nixx@firemail.cc> 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 $destdir = "/file/"; 20 $maxsize = 12 * 1024 * 1024; // 12 MB 21 22 $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; 23 $url = $protocol.$_SERVER['HTTP_HOST']; 24 25 function is_ani($filename){ 26 if(!($fh = @fopen($filename, 'rb'))) return false; 27 $count = 0; 28 29 while(!feof($fh) && $count < 2){ 30 $chunk = fread($fh, 1024 * 100); 31 $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00\x2C#s', $chunk); 32 } 33 34 fclose($fh); 35 return $count > 1; 36 } 37 38 if($_FILES && ($tmpfile = $_FILES['file']['tmp_name'])){ 39 if($_FILES['file']['size'] > $maxsize){ 40 exit("ERR: Filesize too large.\n"); 41 } 42 43 $mtime = sprintf('%.6f', microtime(true)); 44 $name = substr($mtime, 0, 10) . substr($mtime, 11); 45 46 $origname = $_FILES['file']['name']; 47 $extpos = strripos($origname, '.'); 48 if($extpos){ 49 $ext = strtolower(substr($origname, $extpos + 1)); 50 $name = $name.".".$ext; 51 } 52 53 $isimage = getimagesize($tmpfile) ? true : false; 54 $isani = is_ani($tmpfile); 55 if($isimage && !$is_ani){ 56 $img = new Imagick(realpath($tmpfile)); 57 $profile = $img->getImageProfiles("icc", true); 58 $img->stripImage(); 59 if(!empty($profile)) $img->profileImage("icc", $profile['icc']); 60 $img->writeImage($tmpfile); 61 62 $img->clear(); 63 $img->destroy(); 64 } 65 66 if(move_uploaded_file($tmpfile, getcwd().$destdir.$name)){ 67 echo $url.$destdir.$name."\n"; 68 echo "<br /><a href='".$url.$destdir.$name."'>[Link]</a><br />\n"; 69 }else{ 70 exit("ERR: Upload failed. Error code '".$_FILES['file']['error']."'.\n"); 71 } 72 }else{ 73 ?> 74 <html> 75 <head> 76 <title>tinybox</title> 77 </head> 78 <body> 79 <h1>tinybox</h1> 80 81 <h2>Upload via form:</h2> 82 <form enctype="multipart/form-data" action="index.php" method="POST"> 83 <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $maxsize; ?>" /> 84 <input type="file" name="file" /> 85 <input type="submit" value="Upload" /> 86 </form> 87 88 <h2>Upload via cUrl:</h2> 89 <pre>curl -F file='@somefile.ext' <?php echo $url; ?></pre> 90 91 <p><a href="https://git.concealed.world/tinybox/files.html">Git Repository</a></p> 92 </body> 93 </html> 94 <?php 95 } 96 ?>