bludit/bl-kernel/ajax/upload-files.php

40 lines
1.4 KiB
PHP
Raw Normal View History

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) {
// 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
// File extension
$fileExtension = pathinfo($nextFilename, PATHINFO_EXTENSION);
// Move from temporary directory to uploads folder
rename($_FILES['bluditInputFiles']['tmp_name'][$key], PATH_UPLOADS.$nextFilename);
chmod(PATH_UPLOADS.$nextFilename, 0644);
2018-04-09 22:56:12 +02:00
// Generate Thumbnail
2018-04-09 22:56:12 +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
}
$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.',
'filename'=>$nextFilename,
'absoluteURL'=>$absoluteURL,
'absoluteURLThumbnail'=>$absoluteURLThumbnail,
'absolutePath'=>$absolutePath
2018-04-09 22:56:12 +02:00
)));
?>