Uploading of new photos now fully working.
This commit is contained in:
@@ -14,45 +14,44 @@ class UploadMedia extends HTMLController
|
||||
if (!Registry::get('user')->isAdmin())
|
||||
throw new NotAllowedException();
|
||||
|
||||
$page = new MediaUploader();
|
||||
parent::__construct('Upload new media - ' . SITE_TITLE);
|
||||
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 (isset($_POST['save']))
|
||||
if (!empty($_FILES['uploads']))
|
||||
{
|
||||
if (empty($_FILES) || empty($_FILES['new_asset']))
|
||||
return;
|
||||
|
||||
// Any tags?
|
||||
$new_tags = [];
|
||||
if (isset($_POST['tag']) && is_array($_POST['tag']))
|
||||
{
|
||||
foreach ($_POST['tag'] as $id_tag => $bool)
|
||||
if (is_numeric($id_tag))
|
||||
$new_tags[] = $id_tag;
|
||||
}
|
||||
|
||||
var_dump($_FILES);
|
||||
var_dump($_POST);
|
||||
|
||||
foreach ($_FILES['new_asset']['tmp_name'] as $num => $uploaded_file)
|
||||
$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,
|
||||
'preferred_filename' => $_FILES['new_asset']['name'][$num],
|
||||
'title' => !empty($_POST['title'][$num]) ? $_POST['title'][$num] : null,
|
||||
'filename_to_copy' => $uploaded_file['tmp_name'],
|
||||
'preferred_filename' => $uploaded_file['name'],
|
||||
]);
|
||||
|
||||
$asset->linkTags($new_tags);
|
||||
$new_ids[] = $asset->getId();
|
||||
$asset->linkTags([$tag->id_tag]);
|
||||
}
|
||||
|
||||
// Prevent uploading twice.
|
||||
header('Location: ' . BASEURL . '/uploadmedia/');
|
||||
exit;
|
||||
if (isset($_REQUEST['format']) && $_REQUEST['format'] === 'json')
|
||||
{
|
||||
echo json_encode(['success' => true, 'new_ids' => $new_ids]);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
header('Location: ' . BASEURL . '/uploadmedia/');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user