getError();
}
}
Cache::clear();
if (!empty($success)) {
$Messenger->setSuccess(Text::get('deteledSuccess') . '
' . implode('
', $success));
}
$Messenger->setError(implode('
', $errors));
} else {
$Messenger->setError(Text::get('permissionsDeniedError'));
}
return !$Messenger->getError();
}
/**
* List all files of a page or the shared data directory.
*
* @param string $path
* @return array
*/
public static function list(string $path): array
{
$files = array();
$globGrep = FileSystem::globGrep(
$path . '*.*',
'/\.(' . implode('|', FileUtils::allowedFileTypes()) . ')$/i'
);
foreach ($globGrep as $file) {
$item = array();
if (FileUtils::fileIsImage($file)) {
$image = new Image($file, 600, 600);
$item['thumbnail'] = AM_BASE_URL . $image->file;
$item['width'] = $image->originalWidth;
$item['height'] = $image->originalHeight;
}
$item['mtime'] = date('M j, Y H:i', filemtime($file));
$item['size'] = FileSystem::getFileSize($file);
$item['path'] = $file;
$item['basename'] = basename($file);
$item['caption'] = FileUtils::caption($file);
$item['url'] = Str::stripStart($path, AM_BASE_DIR) . basename($file);
$item['extension'] = FileSystem::getExtension($file);
$files[] = $item;
}
return $files;
}
/**
* Upload single file.
*
* @param object $chunk
* @param string $path
* @param Messenger $Messenger
*/
public static function upload(object $chunk, string $path, Messenger $Messenger): void
{
if (empty($chunk->name) || empty($chunk->dzuuid) || empty($chunk->tmp_name)) {
return;
}
if (!FileSystem::isAllowedFileType($chunk->name)) {
$Messenger->setError(
Text::get('unsupportedFileTypeError') . ' "' .
FileSystem::getExtension($chunk->name) . '"'
);
return;
}
if (!is_writable($path)) {
$Messenger->setError(Text::get('permissionsDeniedError'));
return;
}
$cacheDir = AM_BASE_DIR . AM_DIR_CACHE . '/tmp';
$cache = $cacheDir . '/' . $chunk->dzuuid . '.chunks';
FileSystem::makeDir($cacheDir);
if ($chunk->dzchunkindex === '0' && $chunk->dzchunkbyteoffset === '0') {
self::clearChunks($cacheDir);
move_uploaded_file($chunk->tmp_name, $cache);
} else {
$bufferSize = intval($chunk->dzchunksize);
$cacheHandle = fopen($cache, 'a+');
$tmpHandle = fopen($chunk->tmp_name, 'rb');
fwrite($cacheHandle, fread($tmpHandle, $bufferSize));
fclose($tmpHandle);
fclose($cacheHandle);
unlink($chunk->tmp_name);
}
if (intval($chunk->dztotalchunkcount) - 1 === intval($chunk->dzchunkindex)) {
$target = $path . Str::slug($chunk->name);
rename($cache, $target);
Cache::clear();
}
}
/**
* Remove all unfinished uploads that exceeded a given lifetime in seconds.
*
* @param string $dir
* @param int $lifetime
*/
private static function clearChunks(string $dir, int $lifetime = 1200): void
{
$dir = rtrim($dir, '/');
if (!$dir) {
return;
}
$files = FileSystem::glob(rtrim($dir) . '/*.chunks');
foreach ($files as $file) {
if (filemtime($file) < time() - $lifetime) {
unlink($file);
Debug::log($file);
}
}
}
}
__halt_compiler();----SIGNATURE:----NWbgqL3/3rFc/6dkwtucCFHbl8Xy55U3Umpf1q1kWSKzD7TlwW3WUzG5Jidayuu6hitEtJKM6GvxZuWdTgkkjluBC/DxblYbFAH3zPrGgNOOWvWq3HJ/prtMiVyraIdfAwG70PMlMoXdL3Re3vipVFDtc3bAv070mHTfWLggTO7K85y2hEh0B9EaQ818wgLVqZ0BgHfV5wCXLgnhvajEA0qcMyHsG2SEXW3F5KuvRH8gYCYOqK2ZKua30aGT+Y/YrdPMS/0E08ELDADMLRp64S2/lEbj+vK+92AOtxciwDgnHAMx1g2DfMkU8XdjQLe4YD798LpwxtWrzyCoEoVrnwVoblVL6gYIJ9qGlORpk5IjtE87nL1K1j+l4T34axyHT8O82VtQhBMTxH4kmx98zEtTH4BVJeQyQoN/dxi+FbSRHG5JE1AMC77M3Er1Lho4BV5zupo8VSdKfdNZSgqaXhArApAkF3chvMDEeS28wNj2bdGHOqNkmYyqV/88U0gZaRd0JKXtDQeeWZpCm8oVOoXXpIV7QgJ9wfl+xen0WnzcUzrxq8HScvT6Wu9181f/OjNaSinlS0XisESWxSHw8mX1ZNU3h9/IjC7fXHdc3i3GstRpYyJzowBjtTNsFIpNIctwtKL2M+Jg2DgtO86SQ1q/xGSgeQicadjT1oi5MiU=----ATTACHMENT:----MjE5NTk3ODMyOTAwMDQ0NCAxMDYzNzE1NzEzOTY2OTcwIDk1MjI1NjMyNzQ4NTAwMjg=