isLoggedIn()) 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]); if (empty($tag->id_asset_thumb)) { $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; } } } }