ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilFileDelivery.php
Go to the documentation of this file.
1 <?php
2 require_once('./Services/FileDelivery/classes/FileDeliveryTypes/FileDeliveryTypeFactory.php');
3 require_once './Services/FileDelivery/classes/FileDeliveryTypes/DeliveryMethod.php';
4 require_once('./Services/FileDelivery/classes/Delivery.php');
5 require_once('./Services/FileDelivery/interfaces/int.ilFileDeliveryService.php');
6 require_once './Services/FileDelivery/classes/HttpServiceAware.php';
7 
12 
21 final class ilFileDelivery implements ilFileDeliveryService
22 {
23  use HttpServiceAware;
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 }
static returnASCIIFileName($original_filename)
Converts a UTF-8 filename to ASCII.UFT8-Filenamestring ASCII-Filename
PHP
Definition: index.php:3
__construct($filePath)
ilFileDelivery constructor.
static streamVideoInline($path_to_file, $download_file_name='')
void
if($format !==null) $name
Definition: metadata.php:146
static http()
Fetches the global http state from ILIAS.
static deliverFileAttached($path_to_file, $download_file_name='', $mime_type='', $delete_file=false)
void
static deliverFileInline($path_to_file, $download_file_name='')
void
$text
Definition: errorreport.php:18
Create styles array
The data for the language used.
static isNonEmptyString($text)
Checks if the string is not empty.
__call($name, array $arguments)
Workaround because legacy components try to call methods which are moved to the Deliver class...
trait HttpServiceAware
Trait HttpServiceAware.
Class ilFileDelivery.