case 'height': if (!$params) { break; } if (!preg_match('/^[0-9]+$/', $params)) { if (!Settings::isProductionState()) { exit('Error processing params for action "height". Example: 640'); } die; } $check_size_allowed($params); list($width, $height) = getimagesize($src_path); $h = $params; $ratio = $height / $h; $w = $width / $ratio; $image->resize($w, $h); break; case 'width': if (!$params) { break; } if (!preg_match('/^[0-9]+$/', $params)) { if (!Settings::isProductionState()) { exit('Error processing params for action "width". Example: 640'); } die; } $check_size_allowed($params); list($width, $height) = getimagesize($src_path); $w = $params; $ratio = $width / $w;
/** * 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'); }