Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.40 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Config
  5.  **/
  6.  $uploadFolder ='./../dare.ga/public_html/qip-shots';
  7.  $uploadPublic = 'http://dare.ga/qip-shots';
  8.  
  9. /**
  10.  * Fix multidimentional _FILES array values
  11.  * @param array $_files
  12.  * @return array
  13.  */
  14. if (!empty($_FILES)) {
  15.  
  16.     function fix_upload_files_array(array $_files) {
  17.         $files = array();
  18.         foreach ($_files as $name => $file) {
  19.             if (isset($file['name']) && is_array($file['name'])) {
  20.                 foreach (array_keys($file['name']) as $key) {
  21.                     $files[$name][$key] = array(
  22.                         'name' => $file['name'][$key],
  23.                         'type' => $file['type'][$key],
  24.                         'tmp_name' => $file['tmp_name'][$key],
  25.                         'error' => $file['error'][$key],
  26.                         'size' => $file['size'][$key],
  27.                     );
  28.                     $files[$name] = fix_upload_files_array($files[$name]);
  29.                 }
  30.             } else {
  31.                 $files[$name] = $file;
  32.             }
  33.         }
  34.         return $files;
  35.     }
  36.  
  37.     $_FILES = fix_upload_files_array($_FILES);
  38. }
  39.  
  40.  
  41.  
  42. /**
  43.  * Upload file here
  44.  **/
  45. if (
  46.     isset($_REQUEST['act']) &&
  47.     isset($_FILES['files'][0]) &&
  48.     (int)$_FILES['files'][0]['error'] == 0
  49. ){
  50.    
  51.     list($type, $ext) = explode('/', $_FILES['files'][0]['type']); // image/png image/jpeg image/gif
  52.    
  53.     if (
  54.             $type === 'image' &&  // check
  55.             in_array($ext, array('png', 'jpeg', 'gif')) && // mime
  56.             getimagesize($_FILES['files'][0]['tmp_name']) !== FALSE // try 2 load as image
  57.         ){
  58.        
  59.        
  60.         $hash = md5_file($_FILES['files'][0]['tmp_name']);
  61.  
  62.        
  63.         // hash2path
  64.         $path  = preg_replace('#^(\w{3})(\w{3})(\w{3})(.+)$#Ui', '$1/$2/$3/$4', "$hash.$ext");
  65.        
  66.         // Make dir if not exists
  67.         $dir = dirname("$uploadFolder/$path");
  68.        
  69.         if (!is_dir($dir)){
  70.             mkdir($dir, 0777, true);
  71.         }
  72.        
  73.         if (move_uploaded_file($_FILES['files'][0]['tmp_name'], "$uploadFolder/$path")){
  74.             echo "   ";
  75.             echo "$uploadPublic/$path\n";
  76.             echo "$uploadPublic/$path\n";
  77.             echo "$uploadPublic/delete/?hash=$hash\n";
  78.             echo "$uploadPublic/$path\n";
  79.            
  80.             file_put_contents('history.txt', implode(';', array(
  81.                 date('Y-m-d H:i:s'), // date,
  82.                 "$uploadFolder/$path", // local path,
  83.                 "$uploadPublic/$path", // web path
  84.                 "$type/$ext",
  85.                 $_SERVER['REMOTE_ADDR']
  86.             )) . "\r\n", FILE_APPEND);
  87.            
  88.             die();
  89.         }
  90.     }
  91. }
  92.  
  93. die("\r\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement