Exemplo n.º 1
0
            }
            $save_ext = $params;
            break;
        case 'watermark':
            if (!$params) {
                break;
            }
            $check_size_allowed($params);
            if (!preg_match('/^[0-9]+$/', $params)) {
                if (!Settings::isProductionState()) {
                    exit('Error processing params for action "watermark". Example: 1 or main');
                }
                die;
            }
            $data = q_assoc_row('SELECT `image`, `image_pos` FROM `cms_img_proc_perms` WHERE `rule` = "&watermark=' . sql_prepare($params) . '" LIMIT 1');
            if (!$data || !$data['image'] || !$data['image_pos']) {
                if (!Settings::isProductionState()) {
                    exit('Error. Incorrect parameters for action "watermark"');
                }
                die;
            }
            $image->watermark($data['image'], $data['image_pos']);
            break;
    }
}
FileSystem::mkdir(DIR_CACHE . 'images/' . $path);
if (!$image->save(DIR_CACHE . 'images/' . QUERY, $ext, 90) && !Settings::isProductionState()) {
    dump('Not enough memory to resize and sharpen image "' . $path . $file . '".');
}
unset($image);
go('/' . QUERY);
Exemplo n.º 2
0
 /**
  * Action for Upload files using uploader plugin with multiple files and partial uploads
  */
 public function _upload_multiple()
 {
     $if_file_exists = $_GET['exists'];
     $extract_zips = isset($_GET['extract']) && $_GET['extract'] && class_exists('ZipArchive');
     $allowed_extensions = isset($_GET['allowed_extensions']) ? array_filter(explode(',', $_GET['allowed_extensions'])) : [];
     // Current path in chage
     $dir = $_GET['path'];
     $tmp = explode('/', $dir);
     $dir = [];
     foreach ($tmp as $v) {
         if ($v) {
             $dir[] = $v;
         }
     }
     $dir = implode('/', $dir);
     if ($dir) {
         $dir .= '/';
     }
     if ($dir && $dir[0] == '/') {
         $dir = substr($dir, 1);
     }
     $targetDir = DIR_BASE . $dir;
     // Get a file name
     if (isset($_REQUEST["name"])) {
         $fileName = $_REQUEST["name"];
     } elseif (!empty($_FILES)) {
         $fileName = $_FILES["file"]["name"];
     } else {
         $fileName = uniqid('file_');
     }
     // Check file is allowed
     if ($allowed_extensions) {
         $ext = pathinfo($fileName, PATHINFO_EXTENSION);
         if (!in_array($ext, $allowed_extensions)) {
             error('Extension "' . $ext . '" is not allowed');
         }
     }
     //        $fileName = strtolower($fileName);
     $fileName = Converter::data2words(strtolower($fileName), ['@', '-', '_', '.']);
     $filePath = $targetDir . $fileName;
     // Behaviour if file already exists on server
     if (file_exists($filePath)) {
         switch ($if_file_exists) {
             default:
             case 'skip':
                 // End upload
                 ob_get_clean();
                 die('1');
             case 'overwrite':
                 // Do nothing - file will be overwritten
                 break;
             case 'rename':
                 // Generate new name
                 $f_name = pathinfo($filePath, PATHINFO_FILENAME);
                 $f_ext = pathinfo($filePath, PATHINFO_EXTENSION);
                 $name_iterator = 1;
                 while (is_file($filePath)) {
                     $filePath = DIR_BASE . $dir . $f_name . '_' . $name_iterator . '.' . $f_ext;
                     ++$name_iterator;
                 }
                 break;
         }
     }
     // Chunking might be enabled
     $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
     $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
     // Open temp file
     if (!($out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb"))) {
         error('Failed to open output stream.');
     }
     if (!empty($_FILES)) {
         if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
             error('Failed to move uploaded file.');
         }
         // Read binary input stream and append it to temp file
         if (!($in = @fopen($_FILES["file"]["tmp_name"], "rb"))) {
             error('Failed to open input stream.');
         }
     } else {
         if (!($in = @fopen("php://input", "rb"))) {
             error('Failed to open input stream.');
         }
     }
     // Save file from chunks
     while ($buff = fread($in, 4096)) {
         fwrite($out, $buff);
     }
     @fclose($out);
     @fclose($in);
     // Check if file has been uploaded
     if (!$chunks || $chunk == $chunks - 1) {
         // Strip the temp .part suffix off
         rename("{$filePath}.part", $filePath);
     }
     $extention = pathinfo($filePath, PATHINFO_EXTENSION);
     // Resizeimages and remove EXIF meta
     if (in_array($extention, ['jpg', 'jpeg', 'png', 'gif'])) {
         $image = new Image();
         $image->open($filePath);
         list($width, $height) = getimagesize($filePath);
         if ($width > 4096) {
             // Maximim is for 4k screens 4096x3072
             $w = 4096;
             $ratio = $width / $w;
             $h = $height / $ratio;
             $image->resize($w, $h);
             $image->save($filePath, $extention, 90);
         }
     }
     // Extract ZIPs
     if ($extract_zips && pathinfo($filePath, PATHINFO_EXTENSION) === 'zip') {
         // Unzip
         $zip = new ZipArchive();
         $zip_open_result = $zip->open($filePath);
         if ($zip_open_result === true) {
             $zip->extractTo(rtrim($targetDir, '/'));
             $zip->close();
             // Delete archive
             unlink($filePath);
         } else {
             dump('ZipArchive failed to open ' . $filePath . '. With error code - ' . $zip_open_result);
         }
     }
     ob_get_clean();
     die('1');
 }