ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilFileDelivery.php
Go to the documentation of this file.
1<?php
2require_once('./Services/FileDelivery/classes/FileDeliveryTypes/FileDeliveryTypeFactory.php');
3require_once './Services/FileDelivery/classes/FileDeliveryTypes/DeliveryMethod.php';
4require_once('./Services/FileDelivery/classes/Delivery.php');
5require_once('./Services/FileDelivery/interfaces/int.ilFileDeliveryService.php');
6require_once './Services/FileDelivery/classes/HttpServiceAware.php';
7
12
22{
24 const DIRECT_PHP_OUTPUT = Delivery::DIRECT_PHP_OUTPUT;
25 const DELIVERY_METHOD_XSENDFILE = DeliveryMethod::XSENDFILE;
26 const DELIVERY_METHOD_XACCEL = DeliveryMethod::XACCEL;
28 const DELIVERY_METHOD_PHP_CHUNKED = DeliveryMethod::PHP_CHUNKED;
29 const DISP_ATTACHMENT = Delivery::DISP_ATTACHMENT;
30 const DISP_INLINE = Delivery::DISP_INLINE;
34 private $delivery;
35
36
42 public function __construct($filePath)
43 {
44 assert(is_string($filePath));
45 $this->delivery = new Delivery($filePath, self::http());
46 }
47
48
52 public static function deliverFileAttached($path_to_file, $download_file_name = '', $mime_type = '', $delete_file = false)
53 {
54 assert(is_string($path_to_file));
55 assert(is_string($download_file_name));
56 assert(is_string($mime_type));
57 assert(is_bool($delete_file));
58
59 $obj = new Delivery($path_to_file, self::http());
60
61 if (self::isNonEmptyString($download_file_name)) {
62 $obj->setDownloadFileName($download_file_name);
63 }
64 if (self::isNonEmptyString($mime_type)) {
65 $obj->setMimeType($mime_type);
66 }
67 $obj->setDisposition(self::DISP_ATTACHMENT);
68 $obj->setDeleteFile($delete_file);
69 $obj->deliver();
70 }
71
72
76 public static function streamVideoInline($path_to_file, $download_file_name = '')
77 {
78 assert(is_string($path_to_file));
79 assert(is_string($download_file_name));
80 $obj = new Delivery($path_to_file, self::http());
81 if (self::isNonEmptyString($download_file_name)) {
82 $obj->setDownloadFileName($download_file_name);
83 }
84 $obj->setDisposition(self::DISP_INLINE);
85 $obj->stream();
86 }
87
88
92 public static function deliverFileInline($path_to_file, $download_file_name = '')
93 {
94 assert(is_string($path_to_file));
95 assert(is_string($download_file_name));
96 $obj = new Delivery($path_to_file, self::http());
97
98 if (self::isNonEmptyString($download_file_name)) {
99 $obj->setDownloadFileName($download_file_name);
100 }
101 $obj->setDisposition(self::DISP_INLINE);
102 $obj->deliver();
103 }
104
105
109 public static function returnASCIIFileName($original_filename)
110 {
111 assert(is_string($original_filename));
112
113 return Delivery::returnASCIIFileName($original_filename);
114 }
115
116
125 public function __call($name, array $arguments)
126 {
127 assert(is_string($name));
128 //forward call to Deliver class
129 call_user_func_array([ $this->delivery, $name ], $arguments);
130 }
131
132
140 private static function isNonEmptyString($text)
141 {
142 assert(is_string($text));
143
144 return (bool) strcmp($text, '') !== 0;
145 }
146}
An exception for terminatinating execution or to throw for unit testing.
Class ilFileDelivery.
static deliverFileAttached($path_to_file, $download_file_name='', $mime_type='', $delete_file=false)
void
static isNonEmptyString($text)
Checks if the string is not empty.
__construct($filePath)
ilFileDelivery constructor.
static deliverFileInline($path_to_file, $download_file_name='')
void
__call($name, array $arguments)
Workaround because legacy components try to call methods which are moved to the Deliver class.
static returnASCIIFileName($original_filename)
Converts a UTF-8 filename to ASCII.string ASCII-Filename
static streamVideoInline($path_to_file, $download_file_name='')
void
PHP
Definition: index.php:3
trait HttpServiceAware
Trait HttpServiceAware.
static http()
Fetches the global http state from ILIAS.
$text
Definition: errorreport.php:18