62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?php
|
|
/*****************************************************************************
|
|
* UploadMedia.php
|
|
* Contains the media uploading controller
|
|
*
|
|
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
|
*****************************************************************************/
|
|
|
|
class UploadMedia extends HTMLController
|
|
{
|
|
public function __construct()
|
|
{
|
|
// Ensure it's just admins at this point.
|
|
if (!Registry::get('user')->isAdmin())
|
|
throw new NotAllowedException();
|
|
|
|
if (!isset($_REQUEST['tag']))
|
|
throw new UserFacingException('No album tag provided.');
|
|
|
|
$tag = Tag::fromId($_REQUEST['tag']);
|
|
|
|
$page = new MediaUploader($tag);
|
|
parent::__construct('Upload new photos - ' . SITE_TITLE);
|
|
$this->page->adopt($page);
|
|
|
|
// Are we saving something?
|
|
if (!empty($_FILES['uploads']))
|
|
{
|
|
$files = isset($_FILES['uploads'][0]) ? $_FILES['uploads'] : [$_FILES['uploads']];
|
|
$new_ids = [];
|
|
foreach ($files as $num => $uploaded_file)
|
|
{
|
|
if (empty($uploaded_file))
|
|
continue;
|
|
|
|
$asset = Asset::createNew([
|
|
'filename_to_copy' => $uploaded_file['tmp_name'],
|
|
'preferred_filename' => $uploaded_file['name'],
|
|
'preferred_subdir' => $tag->slug,
|
|
]);
|
|
|
|
$new_ids[] = $asset->getId();
|
|
$asset->linkTags([$tag->id_tag]);
|
|
|
|
$tag->id_asset_thumb = $asset->getId();
|
|
$tag->save();
|
|
}
|
|
|
|
if (isset($_REQUEST['format']) && $_REQUEST['format'] === 'json')
|
|
{
|
|
echo json_encode(['success' => true, 'new_ids' => $new_ids]);
|
|
exit;
|
|
}
|
|
else
|
|
{
|
|
header('Location: ' . BASEURL . '/uploadmedia/');
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|