2018-10-06 19:39:34 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
|
|
// $_POST
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// (string) $_POST['uuid']
|
|
|
|
$uuid = empty($_POST['uuid']) ? false : $_POST['uuid'];
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Set upload directory
|
|
|
|
if ($uuid && IMAGE_RESTRICT) {
|
|
|
|
$uploadDirectory = PATH_UPLOADS_PAGES.$uuid.DS;
|
|
|
|
$thumbnailDirectory = $uploadDirectory.'thumbnails'.DS;
|
|
|
|
} else {
|
|
|
|
$uploadDirectory = PATH_UPLOADS;
|
|
|
|
$thumbnailDirectory = PATH_UPLOADS_THUMBNAILS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create directory for images
|
|
|
|
if (!is_dir($uploadDirectory)){
|
|
|
|
Filesystem::mkdir($uploadDirectory, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create directory for thumbnails
|
|
|
|
if (!is_dir($thumbnailDirectory)){
|
|
|
|
Filesystem::mkdir($thumbnailDirectory, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// File extensions allowed
|
|
|
|
$allowedExtensions = array('gif', 'png', 'jpg', 'jpeg', 'svg');
|
|
|
|
|
|
|
|
// Upload all images
|
|
|
|
foreach ($_FILES['bluditInputFiles']['name'] as $key=>$filename) {
|
|
|
|
|
|
|
|
// Check for errors
|
|
|
|
if ($_FILES['bluditInputFiles']['error'][$key] != 0) {
|
2019-02-02 16:11:36 +01:00
|
|
|
$message = $L->g('Maximum load file size allowed:').' '.ini_get('upload_max_filesize');
|
2018-10-06 19:39:34 +02:00
|
|
|
Log::set($message, LOG_TYPE_ERROR);
|
2019-01-30 23:15:36 +01:00
|
|
|
ajaxResponse(1, $message);
|
2018-10-06 19:39:34 +02:00
|
|
|
}
|
|
|
|
|
2019-01-11 17:43:37 +01:00
|
|
|
// Convert URL characters such as spaces or quotes to characters
|
|
|
|
$filename = urldecode($filename);
|
|
|
|
|
2018-10-06 19:39:34 +02:00
|
|
|
// Check file extension
|
|
|
|
$fileExtension = pathinfo($filename, PATHINFO_EXTENSION);
|
2018-11-21 22:48:34 +01:00
|
|
|
$fileExtension = Text::lowercase($fileExtension);
|
2018-10-06 19:39:34 +02:00
|
|
|
if (!in_array($fileExtension, $allowedExtensions) ) {
|
2019-02-02 16:11:36 +01:00
|
|
|
$message = $L->g('File type is not supported. Allowed types:').' '.implode(', ',$allowedExtensions);
|
2018-10-06 19:39:34 +02:00
|
|
|
Log::set($message, LOG_TYPE_ERROR);
|
2019-01-30 23:15:36 +01:00
|
|
|
ajaxResponse(1, $message);
|
2018-10-06 19:39:34 +02:00
|
|
|
}
|
|
|
|
|
2018-11-21 22:48:34 +01:00
|
|
|
// Generate the next filename to not overwrite the original file
|
2018-10-06 19:39:34 +02:00
|
|
|
$nextFilename = Filesystem::nextFilename($uploadDirectory, $filename);
|
|
|
|
|
|
|
|
// Move from temporary directory to uploads folder
|
|
|
|
rename($_FILES['bluditInputFiles']['tmp_name'][$key], $uploadDirectory.$nextFilename);
|
|
|
|
chmod($uploadDirectory.$nextFilename, 0644);
|
|
|
|
|
|
|
|
// Generate Thumbnail
|
|
|
|
// Exclude generate thumbnail for SVG format and generate a symlink to the svg
|
|
|
|
if ($fileExtension == 'svg') {
|
|
|
|
symlink($uploadDirectory.$nextFilename, $thumbnailDirectory.$nextFilename);
|
|
|
|
} else {
|
|
|
|
$Image = new Image();
|
2018-11-25 17:52:22 +01:00
|
|
|
$Image->setImage($uploadDirectory.$nextFilename, $site->thumbnailWidth(), $site->thumbnailHeight(), 'crop');
|
|
|
|
$Image->saveImage($thumbnailDirectory.$nextFilename, $site->thumbnailQuality(), true);
|
2018-10-06 19:39:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-30 23:15:36 +01:00
|
|
|
ajaxResponse(0, 'List of files and number of chunks.', array(
|
2018-10-06 19:39:34 +02:00
|
|
|
'filename'=>$nextFilename
|
2019-01-30 23:15:36 +01:00
|
|
|
));
|
2018-10-06 19:39:34 +02:00
|
|
|
|
|
|
|
?>
|