本文整理汇总了PHP中Books::import方法的典型用法代码示例。如果您正苦于以下问题:PHP Books::import方法的具体用法?PHP Books::import怎么用?PHP Books::import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Books
的用法示例。
在下文中一共展示了Books::import方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importPage
function importPage()
{
if (!isLogged()) {
header('Location: ' . Path::signin() . '&target=import');
exit;
}
global $tpl;
if (isset($_GET['imported'])) {
$tpl->assign('imported', TRUE);
} else {
if (!empty($_FILES)) {
if (!empty($_POST['token']) && acceptToken($_POST['token'])) {
try {
$ext_array = explode('.', $_FILES['file']['name']);
$extension = end($ext_array);
$mime = $_FILES['file']['type'];
// check extension et mime type
if ($extension != 'json') {
throw new \Exception('<br />Extension of the file is not allowed! Please import a JSON file.');
}
if (!($mime == 'application/octet-stream' || $mime == 'application/json')) {
throw new \Exception('<br />MIME type of the file is not allowed! Please import a JSON file.');
}
$file = file_get_contents($_FILES['file']['tmp_name']);
if (!$file) {
throw new \Exception('An error occured while reading the file.');
}
$result = Books::import($file, isset($_POST['keep_ids']), isLogged());
if (!$result) {
throw new \Exception('An error occured while importing the file.');
}
header('Location: ' . Path::import() . '&imported');
exit;
} catch (\Exception $e) {
$tpl->assign('error', $e->getMessage());
}
} else {
errorPage('The received token was empty or invalid.', 'Invalid security token');
}
}
}
$tpl->assign('page_title', 'Import books');
$tpl->assign('menu_links', Path::menu('import'));
$tpl->assign('menu_links_admin', Path::menuAdmin('admin'));
$tpl->assign('token', getToken());
$tpl->draw('admin.import');
exit;
}