コード例 #1
0
        }
        if ($ort == 3 || $ort == 4) {
            $img = imagerotate($img, 180, null);
        }
        if ($ort == 8 || $ort == 7) {
            $img = imagerotate($img, 90, null);
        }
        if ($ort == 5 || $ort == 4 || $ort == 7) {
            imageflip($img, IMG_FLIP_HORIZONTAL);
        }
        imageJPEG($img, DIR_BASE . $src_path, 100);
    }
}
$max_w = 2400;
$max_h = 1600;
$image = new Image();
try {
    $image->open($src_path);
} catch (Exception $e) {
    if (!Settings::isProductionState()) {
        exit('Error. Not enough memory to open image "' . $path . $file . '".');
    }
    die;
}
// If key is provided - no limitations
$check_for_sizes = !isset($_GET['key']) || $_GET['key'] != Configuration::getInstance()->get('cms')['unique_key'];
$allowed_sizes = Settings::get('image_processor_allowed_sizes');
if (!$allowed_sizes && $check_for_sizes) {
    if (!Settings::isProductionState()) {
        exit('Error. No allowed image sizes set.');
    }
コード例 #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');
 }