Elgg  Version master
TempDiskFilestore.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
16 
20  protected $unique_sub_dir;
21 
27  public function __construct($directory_root = '') {
28 
29  if (!$directory_root) {
30  $directory_root = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . '/';
31  }
32 
33  $this->unique_sub_dir = uniqid() . '/';
34 
35  parent::__construct($directory_root);
36  }
37 
47  public function getFilenameOnFilestore(\ElggFile $file): string {
48  $filename = $file->getFilename();
49  if (!$filename) {
50  return '';
51  }
52 
53  return Paths::sanitize($this->dir_root . $this->unique_sub_dir . $file->getFilename(), false);
54  }
55 
59  public function getParameters(): array {
60  $params = parent::getParameters();
61  $params['unique_sub_dir'] = $this->unique_sub_dir;
62 
63  return $params;
64  }
65 
69  public function setParameters(array $parameters): bool {
70 
71  if (isset($parameters['unique_sub_dir'])) {
72  $this->unique_sub_dir = $parameters['unique_sub_dir'];
73  }
74 
75  return parent::setParameters($parameters);
76  }
77 }
__construct($directory_root= '')
Construct a temp disk filestore using the given directory root.
$params
Saves global plugin settings.
Definition: save.php:13
A filestore that uses disk as storage.
getFilename()
Return the filename.
Definition: ElggFile.php:96
getFilenameOnFilestore(\ElggFile $file)
Get the filename as saved on disk for an object.
static sanitize($path, $append_slash=true)
Sanitize file paths ensuring that they begin and end with slashes etc.
Definition: Paths.php:76
A filestore that uses disk as storage.