ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRestFileStorage.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/FileSystem/classes/class.ilFileSystemStorage.php';
5 
13 {
14 
16 
17 
21  public function __construct()
22  {
25  false,
26  0
27  );
28  }
29 
33  protected function getPathPrefix()
34  {
35  return 'ilRestFileStorage';
36  }
37 
41  protected function getPathPostfix()
42  {
43  return 'files';
44  }
45 
49  protected function init()
50  {
51  parent::init();
52  $this->create();
53  }
54 
59  public function getFile($name)
60  {
61  //$return = new stdClass();
62 
63  $GLOBALS['ilLog']->write(__METHOD__.' '.$this->getPath().'/'.$name);
64  if(file_exists($this->getPath().'/'.$name))
65  {
66  $GLOBALS['ilLog']->write(__METHOD__.' file exists');
67  $return = file_get_contents($this->getPath().'/'.$name);
68  }
69 
70  // Responce header
71  Slim::getInstance()->response()->header('Content-Type', 'application/json');
72  Slim::getInstance()->response()->body($return);
73  }
74 
79  public function createFile()
80  {
81  $request = Slim::getInstance()->request();
82  $body = $request->post("content");
83 
84  $tmpname = ilUtil::ilTempnam();
85  $path = $this->getPath().'/'.basename($tmpname);
86 
87  $this->writeToFile($body, $path);
88  $return = basename($tmpname);
89 
90  $GLOBALS['ilLog']->write(__METHOD__.' Writing to path '.$path);
91 
92  Slim::getInstance()->response()->header('Content-Type', 'application/json');
93  Slim::getInstance()->response()->body($return);
94  }
95 
96  public function storeFileForRest($content)
97  {
98  $tmpname = ilUtil::ilTempnam();
99  $path = $this->getPath().'/'.basename($tmpname);
100 
101  $this->writeToFile($content, $path);
102  return basename($tmpname);
103  }
104 
105  public function getStoredFilePath($tmpname)
106  {
107  return $this->getPath().'/'.$tmpname;
108  }
109 
113  public function deleteDeprecated()
114  {
115  $max_age = time() - self::AVAILABILITY_IN_DAYS * 24 * 60 * 60;
116  $ite = new DirectoryIterator($this->getPath());
117  foreach($ite as $file)
118  {
119  if($file->getCTime() <= $max_age)
120  {
121  try {
122  @unlink($file->getPathname());
123  }
124  catch(Exception $e) {
125  $GLOBALS['ilLog']->write(__METHOD__.' '. $e->getMessage());
126  }
127  }
128  }
129  }
130 }
131 ?>