ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilFileDelivery.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
9 
10 /******************************************************************************
11  *
12  * This file is part of ILIAS, a powerful learning management system.
13  *
14  * ILIAS is licensed with the GPL-3.0, you should have received a copy
15  * of said license along with the source code.
16  *
17  * If this is not the case or you just want to try ILIAS, you'll find
18  * us at:
19  * https://www.ilias.de
20  * https://github.com/ILIAS-eLearning
21  *
22  *****************************************************************************/
31 final class ilFileDelivery implements ilFileDeliveryService
32 {
33  use HttpServiceAware;
34 
35  public const DIRECT_PHP_OUTPUT = Delivery::DIRECT_PHP_OUTPUT;
36  public const DELIVERY_METHOD_XSENDFILE = DeliveryMethod::XSENDFILE;
37  public const DELIVERY_METHOD_XACCEL = DeliveryMethod::XACCEL;
39  public const DELIVERY_METHOD_PHP_CHUNKED = DeliveryMethod::PHP_CHUNKED;
40  public const DISP_ATTACHMENT = Delivery::DISP_ATTACHMENT;
41  public const DISP_INLINE = Delivery::DISP_INLINE;
43 
49  public function __construct(string $file_path)
50  {
51  $this->delivery = new Delivery($file_path, self::http());
52  }
53 
54  public static function deliverFileAttached(
55  string $path_to_file,
56  ?string $download_file_name = null,
57  ?string $mime_type = null,
58  bool $delete_file = false
59  ): void {
60  $obj = new Delivery($path_to_file, self::http());
61 
62  if ($download_file_name !== null) {
63  $obj->setDownloadFileName($download_file_name);
64  }
65  if ($mime_type !== null) {
66  $obj->setMimeType($mime_type);
67  }
68  $obj->setDisposition(self::DISP_ATTACHMENT);
69  $obj->setDeleteFile($delete_file);
70  $obj->deliver();
71  }
72 
73  public static function streamVideoInline(
74  string $path_to_file,
75  ?string $download_file_name = null
76  ): void {
77  $obj = new Delivery($path_to_file, self::http());
78  if ($download_file_name !== null) {
79  $obj->setDownloadFileName($download_file_name);
80  }
81  $obj->setDisposition(self::DISP_INLINE);
82  $obj->stream();
83  }
84 
85  public static function deliverFileInline(
86  string $path_to_file,
87  ?string $download_file_name = null
88  ): void {
89  $obj = new Delivery($path_to_file, self::http());
90  if ($download_file_name !== null) {
91  $obj->setDownloadFileName($download_file_name);
92  }
93  $obj->setDisposition(self::DISP_INLINE);
94  $obj->deliver();
95  }
96 
97  public static function returnASCIIFileName(string $original_filename): string
98  {
99  return Delivery::returnASCIIFileName($original_filename);
100  }
101 
110  public function __call(string $name, array $arguments)
111  {
112  throw new LogicException('');
113  }
114 
118  public static function deliverFileLegacy(
119  string $a_file,
120  ?string $a_filename = null,
121  ?string $a_mime = null,
122  ?bool $isInline = false,
123  ?bool $removeAfterDelivery = false,
124  ?bool $a_exit_after = true
125  ): void {
126  global $DIC;
127  // should we fail silently?
128  if (!file_exists($a_file)) {
129  return;
130  }
131  $delivery = new Delivery($a_file, $DIC->http());
132 
133  if ($isInline) {
134  $delivery->setDisposition(self::DISP_INLINE);
135  } else {
136  $delivery->setDisposition(self::DISP_ATTACHMENT);
137  }
138 
139  if ($a_mime !== null && $a_mime !== '') {
140  $delivery->setMimeType($a_mime);
141  }
142 
143  $delivery->setDownloadFileName($a_filename);
144  $delivery->setConvertFileNameToAsci((bool) !$DIC->clientIni()->readVariable('file_access', 'disable_ascii'));
145  $delivery->setDeleteFile($removeAfterDelivery);
146  $delivery->setExitAfter($a_exit_after);
147  $delivery->deliver();
148  }
149 }
setConvertFileNameToAsci(bool $convert_file_name_to_asci)
Definition: Delivery.php:332
setDeleteFile(bool $delete_file)
Definition: Delivery.php:523
setMimeType(string $mime_type)
Definition: Delivery.php:260
PHP
Definition: index.php:3
__construct(string $file_path)
ilFileDelivery constructor.
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
static returnASCIIFileName(string $original_filename)
Converts a UTF-8 filename to ASCII.
static deliverFileInline(string $path_to_file, ?string $download_file_name=null)
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
__call(string $name, array $arguments)
Workaround because legacy components try to call methods which are moved to the Deliver class...
setDisposition(string $disposition)
Definition: Delivery.php:296
static http()
Fetches the global http state from ILIAS.
static deliverFileAttached(string $path_to_file, ?string $download_file_name=null, ?string $mime_type=null, bool $delete_file=false)
setExitAfter(bool $exit_after)
Definition: Delivery.php:320
setDownloadFileName(string $download_file_name)
Definition: Delivery.php:284
Class Delivery.
Definition: Delivery.php:37
static streamVideoInline(string $path_to_file, ?string $download_file_name=null)
trait HttpServiceAware
Trait HttpServiceAware.
Class ilFileDelivery.