2015-11-15 22:37:34 +01:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
|
|
// Type
|
2015-11-17 03:45:03 +01:00
|
|
|
$type = 'other';
|
|
|
|
if(!empty($_POST['type'])) {
|
|
|
|
$type = Sanitize::html($_POST['type']);
|
|
|
|
}
|
2015-11-04 01:28:11 +01:00
|
|
|
|
2015-12-28 23:28:42 +01:00
|
|
|
// Source.
|
2015-11-04 01:28:11 +01:00
|
|
|
$source = $_FILES['files']['tmp_name'][0];
|
|
|
|
|
2015-12-28 23:28:42 +01:00
|
|
|
// Filename and extension.
|
2015-11-04 01:28:11 +01:00
|
|
|
$filename = Text::lowercase($_FILES['files']['name'][0]);
|
|
|
|
$fileExtension = pathinfo($filename, PATHINFO_EXTENSION);
|
|
|
|
$filename = pathinfo($filename, PATHINFO_FILENAME);
|
|
|
|
$filename = Text::replace(' ', '', $filename);
|
|
|
|
$filename = Text::replace('_', '', $filename);
|
|
|
|
|
2015-12-28 23:28:42 +01:00
|
|
|
// Generate the next filename if the filename already exist.
|
|
|
|
$tmpName = $filename.'.'.$fileExtension;
|
|
|
|
if( file_exists(PATH_UPLOADS.$tmpName) )
|
2015-11-04 01:28:11 +01:00
|
|
|
{
|
|
|
|
$number = 0;
|
|
|
|
$tmpName = $filename.'_'.$number.'.'.$fileExtension;
|
|
|
|
while(file_exists(PATH_UPLOADS.$tmpName)) {
|
|
|
|
$number++;
|
|
|
|
$tmpName = $filename.'_'.$number.'.'.$fileExtension;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-28 23:28:42 +01:00
|
|
|
// Move from temporary PHP folder to temporary Bludit folder.
|
|
|
|
move_uploaded_file($source, PATH_TMP.'original'.'.'.$fileExtension);
|
2015-11-04 01:28:11 +01:00
|
|
|
|
2015-11-16 00:04:54 +01:00
|
|
|
// --- PROFILE PICTURE ---
|
2015-11-20 05:00:52 +01:00
|
|
|
if($type=='profilePicture')
|
|
|
|
{
|
2015-11-16 00:04:54 +01:00
|
|
|
// Resize and crop profile image.
|
2015-11-20 05:00:52 +01:00
|
|
|
$username = Sanitize::html($_POST['username']);
|
2016-01-02 23:51:12 +01:00
|
|
|
$tmpName = $username.'.png';
|
2015-11-16 00:04:54 +01:00
|
|
|
$Image = new Image();
|
2016-01-02 23:51:12 +01:00
|
|
|
$Image->setImage(PATH_TMP.'original'.'.'.$fileExtension, '400', '400', 'crop');
|
|
|
|
$Image->saveImage(PATH_UPLOADS_PROFILES.$tmpName, 100, false, true);
|
2015-11-15 22:37:34 +01:00
|
|
|
}
|
2015-11-16 00:04:54 +01:00
|
|
|
// --- OTHERS ---
|
2015-11-15 22:37:34 +01:00
|
|
|
else {
|
2015-12-28 23:28:42 +01:00
|
|
|
// Generate the thumbnail
|
|
|
|
$Image = new Image();
|
2016-01-29 13:31:56 +01:00
|
|
|
//Handling all other formats than svg
|
|
|
|
if (strcasecmp($fileExtension, 'svg') != 0) {
|
|
|
|
$Image->setImage(PATH_TMP.'original'.'.'.$fileExtension, THUMBNAILS_WIDTH, THUMBNAILS_HEIGHT, 'crop');
|
|
|
|
$Image->saveImage(PATH_UPLOADS_THUMBNAILS.$tmpName, 100, true);
|
|
|
|
}
|
2015-12-28 23:28:42 +01:00
|
|
|
// Move the original to the upload folder.
|
|
|
|
rename(PATH_TMP.'original'.'.'.$fileExtension, PATH_UPLOADS.$tmpName);
|
2016-01-29 13:31:56 +01:00
|
|
|
|
|
|
|
//If it is a svg file, just save a copy in thumbnail-folder
|
|
|
|
if (strcasecmp($fileExtension, 'svg') == 0) {
|
|
|
|
copy(PATH_UPLOADS.$tmpName, PATH_UPLOADS_THUMBNAILS.$tmpName);
|
|
|
|
}
|
2015-12-28 23:28:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the Bludit temporary file.
|
|
|
|
if(file_exists(PATH_TMP.'original'.'.'.$fileExtension)) {
|
|
|
|
unlink(PATH_TMP.'original'.'.'.$fileExtension);
|
2015-11-15 22:37:34 +01:00
|
|
|
}
|
2015-11-04 01:28:11 +01:00
|
|
|
|
|
|
|
exit(json_encode(array(
|
|
|
|
'status'=>0,
|
2015-11-15 22:37:34 +01:00
|
|
|
'filename'=>$tmpName
|
2015-11-04 01:28:11 +01:00
|
|
|
)));
|
|
|
|
|
2015-12-28 23:28:42 +01:00
|
|
|
?>
|