本文整理汇总了PHP中Import::server方法的典型用法代码示例。如果您正苦于以下问题:PHP Import::server方法的具体用法?PHP Import::server怎么用?PHP Import::server使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Import
的用法示例。
在下文中一共展示了Import::server方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importServer
private function importServer()
{
Module::dependencies(isset($_POST['albumID'], $_POST['path']));
echo Import::server($_POST['albumID'], $_POST['path']);
}
示例2: server
static function server($albumID = 0, $path)
{
global $database, $plugins, $settings;
# Parse path
if (!isset($path)) {
$path = LYCHEE_UPLOADS_IMPORT;
}
if (substr($path, -1) === '/') {
$path = substr($path, 0, -1);
}
if (is_dir($path) === false) {
Log::error($database, __METHOD__, __LINE__, 'Given path is not a directory (' . $path . ')');
return 'Error: Given path is not a directory!';
}
# Skip folders of Lychee
if ($path === LYCHEE_UPLOADS_BIG || $path . '/' === LYCHEE_UPLOADS_BIG || $path === LYCHEE_UPLOADS_MEDIUM || $path . '/' === LYCHEE_UPLOADS_MEDIUM || $path === LYCHEE_UPLOADS_THUMB || $path . '/' === LYCHEE_UPLOADS_THUMB) {
Log::error($database, __METHOD__, __LINE__, 'The given path is a reserved path of Lychee (' . $path . ')');
return 'Error: Given path is a reserved path of Lychee!';
}
$error = false;
$contains['photos'] = false;
$contains['albums'] = false;
# Invoke plugins directly, as instance method not valid here
# Note that updated albumId and path explicitly passed, rather
# than using func_get_args() which will only return original ones
$plugins->activate(__METHOD__ . ":before", array($albumID, $path));
# Get all files
$files = glob($path . '/*');
foreach ($files as $file) {
# It is possible to move a file because of directory permissions but
# the file may still be unreadable by the user
if (!is_readable($file)) {
$error = true;
Log::error($database, __METHOD__, __LINE__, 'Could not read file or directory: ' . $file);
continue;
}
if (@exif_imagetype($file) !== false) {
# Photo
if (!Import::photo($database, $plugins, $settings, $file, $albumID)) {
$error = true;
Log::error($database, __METHOD__, __LINE__, 'Could not import file: ' . $file);
continue;
}
$contains['photos'] = true;
} else {
if (is_dir($file)) {
# Folder
$name = mysqli_real_escape_string($database, basename($file));
$album = new Album($database, null, null, null);
$newAlbumID = $album->add('[Import] ' . $name);
$contains['albums'] = true;
if ($newAlbumID === false) {
$error = true;
Log::error($database, __METHOD__, __LINE__, 'Could not create album in Lychee (' . $newAlbumID . ')');
continue;
}
$import = Import::server($newAlbumID, $file . '/');
if ($import !== true && $import !== 'Notice: Import only contains albums!') {
$error = true;
Log::error($database, __METHOD__, __LINE__, 'Could not import folder. Function returned warning');
continue;
}
}
}
}
# Invoke plugins directly, as instance method not valid here
# Note that updated albumId and path explicitly passed, rather
# than using func_get_args() which will only return original ones
$plugins->activate(__METHOD__ . ":after", array($albumID, $path));
if ($contains['photos'] === false && $contains['albums'] === false) {
return 'Warning: Folder empty or no readable files to process!';
}
if ($contains['photos'] === false && $contains['albums'] === true) {
return 'Notice: Import only contains albums!';
}
return true;
}
示例3: importServer
private function importServer()
{
Module::dependencies(isset($_POST['albumID'], $_POST['path']));
$import = new Import($this->database, $this->plugins, $this->settings);
echo $import->server($_POST['path'], $_POST['albumID']);
}
示例4: server
static function server($albumID = 0, $path, $useTemp = false)
{
global $database, $plugins, $settings;
# Parse path
if (!isset($path)) {
$path = LYCHEE_UPLOADS_IMPORT;
}
if (substr($path, -1) === '/') {
$path = substr($path, 0, -1);
}
if (is_dir($path) === false) {
Log::error($database, __METHOD__, __LINE__, 'Given path is not a directory (' . $path . ')');
return 'Error: Given path is not a directory!';
}
# Skip folders of Lychee
if ($path === LYCHEE_UPLOADS_BIG || $path . '/' === LYCHEE_UPLOADS_BIG || $path === LYCHEE_UPLOADS_THUMB || $path . '/' === LYCHEE_UPLOADS_THUMB) {
Log::error($database, __METHOD__, __LINE__, 'Given path is a reserved path of Lychee (' . $path . ')');
return 'Error: Given path is a reserved path of Lychee!';
}
/*if ($useTemp===true) {
$path = Import::move($database, $path);
if ($path===false) {
Log::error($database, __METHOD__, __LINE__, 'Failed to move import to temporary directory');
return false;
}
}*/
$error = false;
$contains['photos'] = false;
$contains['albums'] = false;
# Get all files
$files = glob($path . '/*');
foreach ($files as $file) {
# It is possible to move a file because of directory permissions but
# the file may still be unreadable by the user
if (!is_readable($file)) {
$error = true;
Log::error($database, __METHOD__, __LINE__, 'Could not read file or directory: ' . $file);
continue;
}
if (@exif_imagetype($file) !== false) {
# Photo
if (!Import::photo($database, $plugins, $settings, $file, $albumID)) {
$error = true;
Log::error($database, __METHOD__, __LINE__, 'Could not import file: ' . $file);
continue;
}
$contains['photos'] = true;
} else {
if (is_dir($file)) {
# Folder
$name = mysqli_real_escape_string($database, basename($file));
$album = new Album($database, null, null, null);
$newAlbumID = $album->add('[Import] ' . $name);
$contains['albums'] = true;
if ($newAlbumID === false) {
$error = true;
Log::error($database, __METHOD__, __LINE__, 'Could not create album in Lychee (' . $newAlbumID . ')');
continue;
}
$import = Import::server($newAlbumID, $file . '/', false);
if ($import !== true && $import !== 'Notice: Import only contains albums!') {
$error = true;
Log::error($database, __METHOD__, __LINE__, 'Could not import folder. Function returned warning');
continue;
}
}
}
}
# Delete tmpdir if import was successful
/*if ($error===false&&$useTemp===true&&file_exists(LYCHEE_DATA . $tmpdirname)) {
if (@rmdir(LYCHEE_DATA . $tmpdirname)===false) Log::error($database, __METHOD__, __LINE__, 'Could not delete temp-folder (' . LYCHEE_DATA . $tmpdirname . ') after successful import');
}*/
if ($contains['photos'] === false && $contains['albums'] === false) {
return 'Warning: Folder empty or no readable files to process!';
}
if ($contains['photos'] === false && $contains['albums'] === true) {
return 'Notice: Import only contains albums!';
}
return true;
}