bludit/kernel/ajax/uploader.php

62 lines
1.5 KiB
PHP
Raw Permalink Normal View History

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
// Source
$source = $_FILES['files']['tmp_name'][0];
// Filename
$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);
if( file_exists(PATH_UPLOADS.$filename.'.'.$fileExtension) )
{
$number = 0;
$tmpName = $filename.'_'.$number.'.'.$fileExtension;
while(file_exists(PATH_UPLOADS.$tmpName)) {
$number++;
$tmpName = $filename.'_'.$number.'.'.$fileExtension;
}
}
if(empty($tmpName)) {
$tmpName = $filename.'.'.$fileExtension;
}
2015-11-16 00:04:54 +01:00
// --- PROFILE PICTURE ---
2015-11-20 05:00:52 +01:00
if($type=='profilePicture')
{
// Move to tmp file
move_uploaded_file($source, PATH_UPLOADS_PROFILES.'tmp'.'.'.$fileExtension);
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']);
$tmpName = $username.'.jpg';
2015-11-16 00:04:54 +01:00
$Image = new Image();
2015-11-20 05:00:52 +01:00
$Image->setImage(PATH_UPLOADS_PROFILES.'tmp'.'.'.$fileExtension, '200', '200', 'crop');
2015-11-16 00:04:54 +01:00
$Image->saveImage(PATH_UPLOADS_PROFILES.$tmpName, 100, true);
2015-11-20 05:00:52 +01:00
// Remove tmp file
unlink(PATH_UPLOADS_PROFILES.'tmp'.'.'.$fileExtension);
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 {
move_uploaded_file($source, PATH_UPLOADS.$tmpName);
}
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
)));
?>