ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilFileDelivery.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
35 final class ilFileDelivery implements ilFileDeliveryService
36 {
37  use HttpServiceAware;
38 
39  public const DIRECT_PHP_OUTPUT = Delivery::DIRECT_PHP_OUTPUT;
40  public const DELIVERY_METHOD_XSENDFILE = DeliveryMethod::XSENDFILE;
41  public const DELIVERY_METHOD_XACCEL = DeliveryMethod::XACCEL;
42  public const DELIVERY_METHOD_PHP = DeliveryMethod::PHP;
43  public const DELIVERY_METHOD_PHP_CHUNKED = DeliveryMethod::PHP_CHUNKED;
44  public const DISP_ATTACHMENT = Delivery::DISP_ATTACHMENT;
45  public const DISP_INLINE = Delivery::DISP_INLINE;
47 
53  public function __construct(string $file_path)
54  {
55  $this->delivery = new Delivery($file_path, self::http());
56  }
57 
58  public static function deliverFileAttached(
59  string $path_to_file,
60  ?string $download_file_name = null,
61  ?string $mime_type = null,
62  bool $delete_file = false
63  ): void {
64  $obj = new Delivery($path_to_file, self::http());
65 
66  if ($download_file_name !== null) {
67  $obj->setDownloadFileName($download_file_name);
68  }
69  if ($mime_type !== null) {
70  $obj->setMimeType($mime_type);
71  }
72  $obj->setDisposition(self::DISP_ATTACHMENT);
73  $obj->setDeleteFile($delete_file);
74  $obj->deliver();
75  }
76 
77  public static function streamVideoInline(
78  string $path_to_file,
79  ?string $download_file_name = null
80  ): void {
81  $obj = new Delivery($path_to_file, self::http());
82  if ($download_file_name !== null) {
83  $obj->setDownloadFileName($download_file_name);
84  }
85  $obj->setDisposition(self::DISP_INLINE);
86  $obj->stream();
87  }
88 
89  public static function deliverFileInline(
90  string $path_to_file,
91  ?string $download_file_name = null
92  ): void {
93  $obj = new Delivery($path_to_file, self::http());
94  if ($download_file_name !== null) {
95  $obj->setDownloadFileName($download_file_name);
96  }
97  $obj->setDisposition(self::DISP_INLINE);
98  $obj->deliver();
99  }
100 
101  public static function returnASCIIFileName(string $original_filename): string
102  {
103  return Delivery::returnASCIIFileName($original_filename);
104  }
105 
114  public function __call(string $name, array $arguments)
115  {
116  throw new LogicException('');
117  }
118 
122  public static function deliverFileLegacy(
123  string $a_file,
124  ?string $a_filename = null,
125  ?string $a_mime = null,
126  ?bool $isInline = false,
127  ?bool $removeAfterDelivery = false,
128  ?bool $a_exit_after = true
129  ): void {
130  global $DIC;
131  // should we fail silently?
132  if (!file_exists($a_file)) {
133  return;
134  }
135  $delivery = new Delivery($a_file, $DIC->http());
136 
137  if ($isInline) {
138  $delivery->setDisposition(self::DISP_INLINE);
139  } else {
140  $delivery->setDisposition(self::DISP_ATTACHMENT);
141  }
142 
143  if ($a_mime !== null && $a_mime !== '') {
144  $delivery->setMimeType($a_mime);
145  }
146 
147  $settings = new General();
148  $delivery->setDownloadFileName($a_filename);
149  $delivery->setConvertFileNameToAsci($settings->isDownloadWithAsciiFileName());
150  $delivery->setDeleteFile($removeAfterDelivery);
151  $delivery->setExitAfter($a_exit_after);
152  $delivery->deliver();
153  }
154 }
setConvertFileNameToAsci(bool $convert_file_name_to_asci)
Definition: Delivery.php:342
setDeleteFile(bool $delete_file)
Definition: Delivery.php:533
setMimeType(string $mime_type)
Definition: Delivery.php:270
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
__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
__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:306
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:330
setDownloadFileName(string $download_file_name)
Definition: Delivery.php:294
Class Delivery.
Definition: Delivery.php:38
static streamVideoInline(string $path_to_file, ?string $download_file_name=null)
trait HttpServiceAware
Trait HttpServiceAware.
Class ilFileDelivery.