2018-04-09 22:56:12 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
|
|
foreach ($_FILES['bluditInputFiles']['name'] as $key=>$filename) {
|
2018-08-18 16:15:38 +02:00
|
|
|
|
|
|
|
if ($_FILES['bluditInputFiles']['error'][$key] != 0) {
|
|
|
|
$message = 'Error occurred uploading the image, max file size allowed: '.ini_get('upload_max_filesize');
|
|
|
|
Log::set($message, LOG_TYPE_ERROR);
|
|
|
|
exit (json_encode(array(
|
|
|
|
'status'=>1,
|
|
|
|
'message'=>$message
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:32:29 +02:00
|
|
|
// Get the next filename if already exist the file to not overwrite the original file
|
|
|
|
$nextFilename = Filesystem::nextFilename(PATH_UPLOADS, $filename);
|
2018-04-09 22:56:12 +02:00
|
|
|
|
2018-04-13 23:32:29 +02:00
|
|
|
// File extension
|
|
|
|
$fileExtension = pathinfo($nextFilename, PATHINFO_EXTENSION);
|
|
|
|
|
|
|
|
// Move from temporary directory to uploads folder
|
|
|
|
rename($_FILES['bluditInputFiles']['tmp_name'][$key], PATH_UPLOADS.$nextFilename);
|
2018-07-13 18:30:42 +02:00
|
|
|
chmod(PATH_UPLOADS.$nextFilename, 0644);
|
2018-04-09 22:56:12 +02:00
|
|
|
|
2018-04-13 23:32:29 +02:00
|
|
|
// Generate Thumbnail
|
2018-04-09 22:56:12 +02:00
|
|
|
|
2018-04-13 23:32:29 +02:00
|
|
|
// Exclude generate thumbnail for SVG format and generate a symlink to the svg
|
|
|
|
if ($fileExtension == 'svg') {
|
|
|
|
symlink(PATH_UPLOADS.$nextFilename, PATH_UPLOADS_THUMBNAILS.$nextFilename);
|
|
|
|
} else {
|
|
|
|
$Image = new Image();
|
|
|
|
$Image->setImage(PATH_UPLOADS.$nextFilename, $GLOBALS['THUMBNAILS_WIDTH'], $GLOBALS['THUMBNAILS_HEIGHT'], 'crop');
|
|
|
|
$Image->saveImage(PATH_UPLOADS_THUMBNAILS.$nextFilename, $GLOBALS['THUMBNAILS_QUALITY'], true);
|
|
|
|
}
|
2018-04-09 22:56:12 +02:00
|
|
|
}
|
|
|
|
|
2018-04-13 23:32:29 +02:00
|
|
|
$absoluteURL = DOMAIN_UPLOADS.$nextFilename;
|
|
|
|
$absoluteURLThumbnail = DOMAIN_UPLOADS_THUMBNAILS.$nextFilename;
|
|
|
|
$absolutePath = PATH_UPLOADS.$nextFilename;
|
|
|
|
|
2018-04-09 22:56:12 +02:00
|
|
|
exit (json_encode(array(
|
|
|
|
'status'=>0,
|
|
|
|
'message'=>'Image uploaded success.',
|
2018-04-13 23:32:29 +02:00
|
|
|
'filename'=>$nextFilename,
|
|
|
|
'absoluteURL'=>$absoluteURL,
|
|
|
|
'absoluteURLThumbnail'=>$absoluteURLThumbnail,
|
|
|
|
'absolutePath'=>$absolutePath
|
2018-04-09 22:56:12 +02:00
|
|
|
)));
|
|
|
|
|
|
|
|
?>
|