ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
ilRestFileStorage Class Reference

File storage handling. More...

+ Inheritance diagram for ilRestFileStorage:
+ Collaboration diagram for ilRestFileStorage:

Public Member Functions

 __construct ()
 Constructor. More...
 
 getFile ($name)
 Get file by md5 hash. More...
 
 createFile ()
 Get file by md5 hash. More...
 
 storeFileForRest ($content)
 
 getStoredFilePath ($tmpname)
 
 deleteDeprecated ()
 Delete deprecated files. More...
 
- Public Member Functions inherited from ilFileSystemStorage
 __construct ($a_storage_type, $a_path_conversion, $a_container_id)
 Constructor. More...
 
 getContainerId ()
 
 create ()
 Create directory. More...
 
 getAbsolutePath ()
 Get absolute path of storage directory. More...
 
 writeToFile ($a_data, $a_absolute_path)
 Write data to file. More...
 
 deleteFile ($a_abs_name)
 Delete file. More...
 
 deleteDirectory ($a_abs_name)
 Delete directory. More...
 
 delete ()
 Delete complete directory. More...
 
 copyFile ($a_from, $a_to)
 Copy files. More...
 
 appendToPath ($a_appendix)
 
 getStorageType ()
 
 getPath ()
 Get path. More...
 
 __construct ($a_storage_type, $a_path_conversion, $a_container_id)
 Constructor. More...
 
 create ()
 Create directory. More...
 
 getAbsolutePath ()
 Get absolute path of storage directory. More...
 
 getShortPath ()
 
 rename ($from, $to)
 

Data Fields

const AVAILABILITY_IN_DAYS = 1
 
- Data Fields inherited from ilFileSystemStorage
const STORAGE_WEB = 1
 
const STORAGE_DATA = 2
 
const STORAGE_SECURED = 3
 
const FACTOR = 100
 
const MAX_EXPONENT = 3
 
const SECURED_DIRECTORY = "sec"
 

Protected Member Functions

 getPathPrefix ()
 Get path prefix. More...
 
 getPathPostfix ()
 Get path prefix. More...
 
 init ()
 init and create directory More...
 
 responeNotFound ()
 Send not found response. More...
 
 getPathPrefix ()
 Get path prefix. More...
 
 getPathPostfix ()
 Get directory name. More...
 
 init ()
 Read path info. More...
 
 getPathPrefix ()
 Get path prefix. More...
 
 getPathPostfix ()
 Get directory name. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ilFileSystemStorage
static _createPathFromId ($a_container_id, $a_name)
 Create a path from an id: e.g 12345 will be converted to 12/34/<name>_5. More...
 
 _copyDirectory ($a_source, $a_target)
 Copy directory and all contents. More...
 
static _createPathFromId ($a_container_id, $a_name)
 Create a path from an id: e.g 12345 will be converted to 12/34/<name>_5. More...
 
- Protected Attributes inherited from ilFileSystemStorage
 $path
 

Detailed Description

File storage handling.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e $Id$

Definition at line 12 of file class.ilRestFileStorage.php.

Constructor & Destructor Documentation

◆ __construct()

ilRestFileStorage::__construct ( )

Constructor.

Definition at line 20 of file class.ilRestFileStorage.php.

21 {
22 parent::__construct(
24 false,
25 0
26 );
27 }

References ilFileSystemStorage\STORAGE_DATA.

Member Function Documentation

◆ createFile()

ilRestFileStorage::createFile ( )

Get file by md5 hash.

Parameters
<type>$name

Definition at line 104 of file class.ilRestFileStorage.php.

105 {
106 $request = Slim::getInstance()->request();
107 $body = $request->post("content");
108
109 $tmpname = ilUtil::ilTempnam();
110 $path = $this->getPath().'/'.basename($tmpname);
111
112 $this->writeToFile($body, $path);
113 $return = basename($tmpname);
114
115 $GLOBALS['ilLog']->write(__METHOD__.' Writing to path '.$path);
116
117 Slim::getInstance()->response()->header('Content-Type', 'application/json');
118 Slim::getInstance()->response()->body($return);
119 }
static getInstance( $name='default')
Get Slim application with name.
Definition: Slim.php:254
writeToFile($a_data, $a_absolute_path)
Write data to file.
static ilTempnam()
Create a temporary file in an ILIAS writable directory.
$GLOBALS['ct_recipient']

References $GLOBALS, ilFileSystemStorage\$path, Slim\getInstance(), ilFileSystemStorage\getPath(), ilUtil\ilTempnam(), and ilFileSystemStorage\writeToFile().

+ Here is the call graph for this function:

◆ deleteDeprecated()

ilRestFileStorage::deleteDeprecated ( )

Delete deprecated files.

Definition at line 138 of file class.ilRestFileStorage.php.

139 {
140 $max_age = time() - self::AVAILABILITY_IN_DAYS * 24 * 60 * 60;
141 $ite = new DirectoryIterator($this->getPath());
142 foreach($ite as $file)
143 {
144 if($file->getCTime() <= $max_age)
145 {
146 try {
147 @unlink($file->getPathname());
148 }
149 catch(Exception $e) {
150 $GLOBALS['ilLog']->write(__METHOD__.' '. $e->getMessage());
151 }
152 }
153 }
154 }
print $file

References $file, $GLOBALS, and ilFileSystemStorage\getPath().

+ Here is the call graph for this function:

◆ getFile()

ilRestFileStorage::getFile (   $name)

Get file by md5 hash.

Parameters
<type>$name

Definition at line 58 of file class.ilRestFileStorage.php.

59 {
60 $GLOBALS['ilLog']->write(__METHOD__.' original name: '.$this->getPath().'/'.$name);
61
62 $real_path = realpath($this->getPath().'/'.$name);
63 if(!$real_path)
64 {
65 $GLOBALS['ilLog']->write(__METHOD__.' no realpath found for: '.$this->getPath().'/'.$name);
66 $this->responeNotFound();
67 return;
68 }
69 $file_name = basename($real_path);
70 $GLOBALS['ilLog']->write(__METHOD__.' translated name: '.$this->getPath().'/'.$file_name);
71 if(
72 $file_name &&
73 is_file($this->getPath().'/'.$file_name) &&
74 file_exists($this->getPath().'/'.$file_name)
75 )
76 {
77 $GLOBALS['ilLog']->write(__METHOD__.' delivering file: ' . $this->getPath().'/'.$file_name);
78 $return = file_get_contents($this->getPath().'/'.$file_name);
79 // Response header
80 Slim::getInstance()->response()->header('Content-Type', 'application/json');
81 Slim::getInstance()->response()->body($return);
82 return;
83 }
84
85 $this->responeNotFound();
86 }
responeNotFound()
Send not found response.

References $GLOBALS, Slim\getInstance(), ilFileSystemStorage\getPath(), and responeNotFound().

+ Here is the call graph for this function:

◆ getPathPostfix()

ilRestFileStorage::getPathPostfix ( )
protected

Get path prefix.

Reimplemented from ilFileSystemStorage.

Definition at line 40 of file class.ilRestFileStorage.php.

41 {
42 return 'files';
43 }

◆ getPathPrefix()

ilRestFileStorage::getPathPrefix ( )
protected

Get path prefix.

Reimplemented from ilFileSystemStorage.

Definition at line 32 of file class.ilRestFileStorage.php.

33 {
34 return 'ilRestFileStorage';
35 }

◆ getStoredFilePath()

ilRestFileStorage::getStoredFilePath (   $tmpname)

Definition at line 130 of file class.ilRestFileStorage.php.

131 {
132 return $this->getPath().'/'.$tmpname;
133 }

References ilFileSystemStorage\getPath().

+ Here is the call graph for this function:

◆ init()

ilRestFileStorage::init ( )
protected

init and create directory

Reimplemented from ilFileSystemStorage.

Definition at line 48 of file class.ilRestFileStorage.php.

49 {
50 parent::init();
51 $this->create();
52 }

References ilFileSystemStorage\create().

+ Here is the call graph for this function:

◆ responeNotFound()

ilRestFileStorage::responeNotFound ( )
protected

Send not found response.

Definition at line 92 of file class.ilRestFileStorage.php.

93 {
94 $GLOBALS['ilLog']->write(__METHOD__.' file not found.');
95 Slim::getInstance()->response()->header('Content-Type','text/html');
96 Slim::getInstance()->response()->status(404);
97 Slim::getInstance()->response()->body('Not found');
98 }

References $GLOBALS, and Slim\getInstance().

Referenced by getFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ storeFileForRest()

ilRestFileStorage::storeFileForRest (   $content)

Definition at line 121 of file class.ilRestFileStorage.php.

122 {
123 $tmpname = ilUtil::ilTempnam();
124 $path = $this->getPath().'/'.basename($tmpname);
125
126 $this->writeToFile($content, $path);
127 return basename($tmpname);
128 }

References ilFileSystemStorage\$path, ilFileSystemStorage\getPath(), ilUtil\ilTempnam(), and ilFileSystemStorage\writeToFile().

+ Here is the call graph for this function:

Field Documentation

◆ AVAILABILITY_IN_DAYS

const ilRestFileStorage::AVAILABILITY_IN_DAYS = 1

Definition at line 14 of file class.ilRestFileStorage.php.


The documentation for this class was generated from the following file: