Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2. ############################################################################
  3. #    PHP Upload Script for ShareX v2.0
  4. #    Copyright (C) 2013 - 2015  Richard Cornwell
  5. #    Website: http://thegeekoftheworld.com/
  6. #    Script:  http://thegeekoftheworld.com/php-upload-script-for-sharex-v2
  7. #    Email:   richard@techtoknow.net
  8. #
  9. #    This program is free software: you can redistribute it and/or
  10. #    modify it under the terms of the GNU General Public License as
  11. #    published by the Free Software Foundation, either version 3 of the
  12. #    License, or (at your option) any later version.
  13. #
  14. #    This program is distributed in the hope that it will be useful,
  15. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. #    GNU General Public License for more details.
  18. #
  19. #    You should have received a copy of the GNU General Public License
  20. #    along with this program. If not, see <http://www.gnu.org/licenses>.
  21. ############################################################################
  22.  
  23. $key = "Changeme";
  24. $redirect = "http://redirectdomain.tld/";
  25. $domain = "thisdomain.tld";
  26. $filenamelength = 4;
  27.  
  28. #Comment this next line if you want Robots to index this site.
  29. if ($_SERVER["REQUEST_URI"] == "/robot.txt") { die("User-agent: *\nDisallow: /"); }
  30.  
  31.  
  32. #Don't edit below this line inless you know what you are doing...
  33. $urldata = explode("/", $_SERVER["REQUEST_URI"]);
  34.  
  35. function createthumb($name,$filename,$new_w,$new_h){
  36.     $system=explode('.',$name);
  37.     $src_img = imagecreatefromstring(file_get_contents($name));
  38.     $old_x=imageSX($src_img);
  39.     $old_y=imageSY($src_img);
  40.     if ($old_x > $old_y) {
  41.         $thumb_w=$new_w;
  42.         $thumb_h=$old_y*($new_h/$old_x);
  43.     }
  44.     if ($old_x < $old_y) {
  45.         $thumb_w=$old_x*($new_w/$old_y);
  46.         $thumb_h=$new_h;
  47.     }
  48.     if ($old_x == $old_y) {
  49.         $thumb_w=$new_w;
  50.         $thumb_h=$new_h;
  51.     }
  52.     $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
  53.     imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
  54.     if (preg_match("/png/",$system[1])){
  55.         imagepng($dst_img,$filename);
  56.     } else {
  57.         imagejpeg($dst_img,$filename);
  58.     }
  59.     imagedestroy($dst_img);
  60.     imagedestroy($src_img);
  61. }
  62.  
  63. if (isset($urldata[1])) {
  64.         if($urldata[1] == "tn") {
  65.         if(!file_exists('tn_'.$urldata[2])) {
  66.             createthumb($urldata[2],'tn_'.$urldata[2],100,100);
  67.         }
  68.         header('Location: http://'.$domain.'/tn_'.$urldata[2]);
  69.         die();
  70.     }
  71. }
  72.  
  73. if (isset($urldata[1])) {
  74.     if ($urldata[1] == $key) {
  75.     header("Content-Type: application/json");
  76.     if($urldata[2] == "upload") {
  77.             $target = getcwd() . "/" . basename($_FILES['d']['name']);
  78.             if (move_uploaded_file($_FILES['d']['tmp_name'], $target)) {
  79.  
  80.             $filename = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 0, $filenamelength).".".end(explode(".", $_FILES["d"]["name"]));
  81.             while(file_exists($filename)) { $filename = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 0, $filenamelength).".".end(explode(".", $_FILES["d"]["name"])); }
  82.                 rename(getcwd() . "/" . basename($_FILES['d']['name']), getcwd() . "/" . $filename);
  83.             echo json_encode(array('filename' => $filename, 'key' => $key));
  84.             } else {
  85.                     echo "Sorry, there was a problem uploading your file.";
  86.             }
  87.     } elseif ($urldata[2] == "delete") {
  88.         if (file_exists($urldata[3])) {
  89.             if (isset($urldata[3])) {
  90.                 if(file_exists('tn_'.$urldata[3])) {
  91.                     unlink('tn_'.$urldata[3]);
  92.                 }
  93.                 unlink($urldata[3]);
  94.                 echo "Your uploaded file has been deleted";
  95.             } else { echo "Your file you want deleted does not exist"; }
  96.         }
  97.     }
  98. } else {
  99.     header('Location: '.$redirect);
  100. }
  101. } else {
  102.     header('Location: '.$redirect);
  103. }
  104. ?>