ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilFileDelivery.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26
36{
37 use HttpServiceAware;
38
42 public const DIRECT_PHP_OUTPUT = Delivery::DIRECT_PHP_OUTPUT;
46 public const DELIVERY_METHOD_XSENDFILE = DeliveryMethod::XSENDFILE;
50 public const DELIVERY_METHOD_XACCEL = DeliveryMethod::XACCEL;
54 public const DELIVERY_METHOD_PHP = DeliveryMethod::PHP;
58 public const DELIVERY_METHOD_PHP_CHUNKED = DeliveryMethod::PHP_CHUNKED;
62 public const DISP_ATTACHMENT = Delivery::DISP_ATTACHMENT;
66 public const DISP_INLINE = Delivery::DISP_INLINE;
68
74 public function __construct(string $file_path)
75 {
76 $this->delivery = new Delivery($file_path, self::http());
77 }
78
79 public static function deliverFileAttached(
80 string $path_to_file,
81 ?string $download_file_name = null,
82 ?string $mime_type = null,
83 bool $delete_file = false
84 ): void {
85 $obj = new Delivery($path_to_file, self::http());
86
87 if ($download_file_name !== null) {
88 $obj->setDownloadFileName($download_file_name);
89 }
90 if ($mime_type !== null) {
91 $obj->setMimeType($mime_type);
92 }
93 $obj->setDisposition(self::DISP_ATTACHMENT);
94 $obj->setDeleteFile($delete_file);
95 $obj->deliver();
96 }
97
98 public static function streamVideoInline(
99 string $path_to_file,
100 ?string $download_file_name = null
101 ): void {
102 $obj = new Delivery($path_to_file, self::http());
103 if ($download_file_name !== null) {
104 $obj->setDownloadFileName($download_file_name);
105 }
106 $obj->setDisposition(self::DISP_INLINE);
107 $obj->stream();
108 }
109
110 public static function deliverFileInline(
111 string $path_to_file,
112 ?string $download_file_name = null
113 ): void {
114 $obj = new Delivery($path_to_file, self::http());
115 if ($download_file_name !== null) {
116 $obj->setDownloadFileName($download_file_name);
117 }
118 $obj->setDisposition(self::DISP_INLINE);
119 $obj->deliver();
120 }
121
122 public static function returnASCIIFileName(string $original_filename): string
123 {
124 return Delivery::returnASCIIFileName($original_filename);
125 }
126
135 public function __call(string $name, array $arguments)
136 {
137 throw new LogicException('');
138 }
139
143 public static function deliverFileLegacy(
144 string $a_file,
145 ?string $a_filename = null,
146 ?string $a_mime = null,
147 ?bool $isInline = false,
148 ?bool $removeAfterDelivery = false,
149 ?bool $a_exit_after = true
150 ): void {
151 global $DIC;
152 // should we fail silently?
153 if (!file_exists($a_file)) {
154 return;
155 }
156 $delivery = new Delivery($a_file, $DIC->http());
157
158 if ($isInline) {
159 $delivery->setDisposition(self::DISP_INLINE);
160 } else {
161 $delivery->setDisposition(self::DISP_ATTACHMENT);
162 }
163
164 if ($a_mime !== null && $a_mime !== '') {
165 $delivery->setMimeType($a_mime);
166 }
167
168 $settings = new General();
169 $delivery->setDownloadFileName($a_filename);
170 $delivery->setConvertFileNameToAsci($settings->isDownloadWithAsciiFileName());
171 $delivery->setDeleteFile($removeAfterDelivery);
172 $delivery->setExitAfter($a_exit_after);
173 $delivery->deliver();
174 }
175}
setExitAfter(bool $exit_after)
Definition: Delivery.php:345
setConvertFileNameToAsci(bool $convert_file_name_to_asci)
Definition: Delivery.php:357
setMimeType(string $mime_type)
Definition: Delivery.php:285
setDisposition(string $disposition)
Definition: Delivery.php:321
setDeleteFile(bool $delete_file)
Definition: Delivery.php:548
setDownloadFileName(string $download_file_name)
Definition: Delivery.php:309
trait HttpServiceAware
Trait HttpServiceAware.
Class ilFileDelivery.
static returnASCIIFileName(string $original_filename)
Converts a UTF-8 filename to ASCII.
__construct(string $file_path)
ilFileDelivery constructor.
static streamVideoInline(string $path_to_file, ?string $download_file_name=null)
static deliverFileAttached(string $path_to_file, ?string $download_file_name=null, ?string $mime_type=null, bool $delete_file=false)
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
__call(string $name, array $arguments)
Workaround because legacy components try to call methods which are moved to the Deliver class.
static deliverFileInline(string $path_to_file, ?string $download_file_name=null)
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26