19 declare(strict_types=1);
28 public function __construct(
private readonly
int $obj_id,
private readonly
int $draft_id)
31 $this->main_tpl = $DIC->ui()->mainTemplate();
32 $this->
lng = $DIC->language();
33 $this->error = $DIC[
'ilErr'];
36 $this->drafts_path = $this->
getPath() .
'/forum/drafts';
56 public function getFiles(): array
60 foreach (
new DirectoryIterator($this->
getDraftsPath() .
'/' . $this->draft_id) as $file) {
67 'path' => $file->getPathname(),
68 'md5' => md5($file->getFilename()),
69 'name' => $file->getFilename(),
70 'size' => $file->getSize(),
71 'ctime' => date(
'Y-m-d H:i:s', $file->getCTime())
85 foreach (
new DirectoryIterator($this->
getDraftsPath() .
'/' . $this->draft_id) as $file) {
94 $files[$file->getFilename()] = [
95 'path' => $file->getPathname(),
96 'md5' => md5($file->getFilename()),
97 'name' => $file->getFilename(),
98 'size' => $file->getSize(),
99 'ctime' => date(
'Y-m-d H:i:s', $file->getCTime())
106 public function delete(array $posting_ids_to_delete = null):
bool 109 if ($posting_ids_to_delete === null) {
113 foreach ($posting_ids_to_delete as $draft_id) {
122 if (isset($files[
'name']) && is_array($files[
'name'])) {
123 foreach ($files[
'name'] as $index => $name) {
124 $name = rtrim($name,
'/');
126 $temp_name = $files[
'tmp_name'][$index];
127 $error = $files[
'error'][$index];
129 if (
$filename !==
'' && $temp_name !==
'' && (
int) $error === 0) {
140 if (isset($files[
'name']) && is_string($files[
'name'])) {
141 $files[
'name'] = rtrim($files[
'name'],
'/');
143 $temp_name = $files[
'tmp_name'];
167 foreach ($files as $file) {
168 if ($file[
'type'] ===
'file' && md5($file[
'entry']) === $hashed_filename) {
170 'path' => $this->
getDraftsPath() .
'/' . $this->draft_id .
'/' . $file[
'entry'],
171 'filename' => $file[
'entry'],
172 'clean_filename' => $file[
'entry']
186 if (is_array($hashedFilenameOrFilenames)) {
187 foreach ($files as $file) {
188 if ($file[
'type'] ===
'file' && in_array(md5($file[
'entry']), $hashedFilenameOrFilenames,
true)) {
189 unlink($this->
getDraftsPath() .
'/' . $this->draft_id .
'/' . $file[
'entry']);
196 foreach ($files as $file) {
197 if ($file[
'type'] ===
'file' && md5($file[
'entry']) === $hashedFilenameOrFilenames) {
198 return unlink($this->
getDraftsPath() .
'/' . $this->draft_id .
'/' . $file[
'entry']);
207 if (!is_dir($this->
getDraftsPath() .
'/' . $this->draft_id)) {
217 if (!is_writable($this->
getDraftsPath() .
'/' . $this->draft_id) ||
218 !is_readable($this->
getDraftsPath() .
'/' . $this->draft_id)) {
219 $this->error->raiseError(
'Forum directory is not readable/writable by webserver', $this->error->FATAL);
237 if (is_file($a_path)) {
248 $this->main_tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'error_reading_file'),
true);
258 $this->main_tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'error_reading_file'),
true);
265 $DIC->http()->close();
274 $tmp_dir = $this->
getDraftsPath() .
'/drafts_zip/' . $this->draft_id;
276 if ($filesOfDraft !== []) {
277 ksort($filesOfDraft);
279 foreach ($filesOfDraft as $file) {
280 copy($file[
'path'], $tmp_dir .
'/' . $file[
'name']);
286 $zip_file = $this->
getDraftsPath() .
'/drafts_zip/' . $this->draft_id .
'.zip';
294 return $this->draft_id;
311 public function ilClone(
int $new_obj_id,
int $new_posting_id): bool
ilClone(int $new_obj_id, int $new_posting_id)
__construct(private readonly int $obj_id, private readonly int $draft_id)
getFileDataByMD5Filename(string $hashed_filename)
deliverFile(string $file)
rotateFiles(string $a_path)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
unlinkFilesByMD5Filenames($hashedFilenameOrFilenames)
ilGlobalTemplateInterface $main_tpl
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
setPosId(int $posting_id)
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
static _sanitizeFilemame(string $a_filename)
Error Handling & global info handling.
unlinkFile(string $filename)
static zip(string $a_dir, string $a_file, bool $compress_content=false)
static rename(string $a_source, string $a_target)
static newInstanceByDraftId(int $draft_id)
moveFilesOfPost(int $new_frm_id=0)
storeUploadedFile(array $files)