mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-23 17:10:53 +01:00
[ticket/15171] Update logic
PHPBB3-15171
This commit is contained in:
parent
7a4dd368b5
commit
837a333ef2
@ -107,7 +107,7 @@ class local implements adapter_interface, stream_interface
|
||||
|
||||
try
|
||||
{
|
||||
$this->filesystem->dump_file($this->root_path . $this->get_subfolder($path) . $path, $content);
|
||||
$this->filesystem->dump_file($this->root_path . $this->get_filepath($path), $content);
|
||||
}
|
||||
catch (filesystem_exception $e)
|
||||
{
|
||||
@ -125,7 +125,7 @@ class local implements adapter_interface, stream_interface
|
||||
throw new exception('STORAGE_FILE_NO_EXIST', $path);
|
||||
}
|
||||
|
||||
$content = @file_get_contents($this->root_path . $this->get_subfolder($path) . $path);
|
||||
$content = @file_get_contents($this->root_path . $this->get_filepath($path));
|
||||
|
||||
if ($content === false)
|
||||
{
|
||||
@ -140,7 +140,7 @@ class local implements adapter_interface, stream_interface
|
||||
*/
|
||||
public function exists($path)
|
||||
{
|
||||
return $this->filesystem->exists($this->root_path . $this->get_subfolder($path) . $path);
|
||||
return $this->filesystem->exists($this->root_path . $this->get_filepath($path));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,7 +150,7 @@ class local implements adapter_interface, stream_interface
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->filesystem->remove($this->root_path . $this->get_subfolder($path) . $path);
|
||||
$this->filesystem->remove($this->root_path . $this->get_filepath($path));
|
||||
}
|
||||
catch (filesystem_exception $e)
|
||||
{
|
||||
@ -169,7 +169,7 @@ class local implements adapter_interface, stream_interface
|
||||
|
||||
try
|
||||
{
|
||||
$this->filesystem->rename($this->root_path . $this->get_subfolder($path) . $path_orig, $this->root_path . $this->get_subfolder($path) . $path_dest, false);
|
||||
$this->filesystem->rename($this->root_path . $this->get_filepath($path_orig), $this->root_path . $this->get_filepath($path_dest), false);
|
||||
}
|
||||
catch (filesystem_exception $e)
|
||||
{
|
||||
@ -188,7 +188,7 @@ class local implements adapter_interface, stream_interface
|
||||
|
||||
try
|
||||
{
|
||||
$this->filesystem->copy($this->root_path . $this->get_subfolder($path) . $path_orig, $this->root_path . $this->get_subfolder($path) . $path_dest, false);
|
||||
$this->filesystem->copy($this->root_path . $this->get_filepath($path_orig), $this->root_path . $this->get_filepath($path_dest), false);
|
||||
}
|
||||
catch (filesystem_exception $e)
|
||||
{
|
||||
@ -222,7 +222,7 @@ class local implements adapter_interface, stream_interface
|
||||
*/
|
||||
protected function ensure_directory_exists($path)
|
||||
{
|
||||
$path = dirname($this->root_path . $this->get_subfolder($path) . $path);
|
||||
$path = dirname($this->root_path . $this->get_filepath($path));
|
||||
$path = filesystem_helper::make_path_relative($path, $this->root_path);
|
||||
|
||||
if (!$this->exists($path))
|
||||
@ -238,8 +238,9 @@ class local implements adapter_interface, stream_interface
|
||||
*/
|
||||
protected function remove_empty_dirs($path)
|
||||
{
|
||||
$path = dirname($this->root_path . $this->get_subfolder($path) . $path);
|
||||
$path = filesystem_helper::make_path_relative($path, $this->root_path);
|
||||
$dirpath = dirname($this->root_path . $path);
|
||||
$filepath = dirname($this->root_path . $this->get_filepath($path));
|
||||
$path = filesystem_helper::make_path_relative($filepath, $dirpath);
|
||||
|
||||
do
|
||||
{
|
||||
@ -247,17 +248,29 @@ class local implements adapter_interface, stream_interface
|
||||
$parts = array_slice($parts, 0, -1);
|
||||
$path = implode(DIRECTORY_SEPARATOR, $parts);
|
||||
}
|
||||
while (@rmdir($this->root_path . $path));
|
||||
while ($path && @rmdir($dirpath . $path));
|
||||
}
|
||||
|
||||
protected function get_subfolder($path)
|
||||
protected function get_filepath($path)
|
||||
{
|
||||
$hash = md5($path);
|
||||
$pathinfo = pathinfo($path);
|
||||
$dirname = $pathinfo['dirname'];
|
||||
$filename = $pathinfo['basename'];
|
||||
|
||||
$hash = md5($filename);
|
||||
|
||||
$parts = str_split($hash, 2);
|
||||
$parts = array_slice($parts, 0, $this->dir_depth);
|
||||
|
||||
return (!empty($parts)) ? implode(DIRECTORY_SEPARATOR, $parts) . DIRECTORY_SEPARATOR : '';
|
||||
// Create path
|
||||
$path = $dirname . DIRECTORY_SEPARATOR;
|
||||
|
||||
if (!empty($parts))
|
||||
{
|
||||
$path .= implode(DIRECTORY_SEPARATOR, $parts) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
return $path . $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -265,7 +278,7 @@ class local implements adapter_interface, stream_interface
|
||||
*/
|
||||
public function read_stream($path)
|
||||
{
|
||||
$stream = @fopen($this->root_path . $this->get_subfolder($path) . $path, 'rb');
|
||||
$stream = @fopen($this->root_path . $this->get_filepath($path), 'rb');
|
||||
|
||||
if (!$stream)
|
||||
{
|
||||
@ -287,7 +300,7 @@ class local implements adapter_interface, stream_interface
|
||||
throw new exception('STORAGE_FILE_EXISTS', $path);
|
||||
}
|
||||
|
||||
$stream = @fopen($this->root_path . $this->get_subfolder($path) . $path, 'w+b');
|
||||
$stream = @fopen($this->root_path . $this->get_filepath($path), 'w+b');
|
||||
|
||||
if (!$stream)
|
||||
{
|
||||
@ -312,7 +325,7 @@ class local implements adapter_interface, stream_interface
|
||||
*/
|
||||
public function file_size($path)
|
||||
{
|
||||
$size = filesize($this->root_path . $this->get_subfolder($path) . $path);
|
||||
$size = filesize($this->root_path . $this->get_filepath($path));
|
||||
|
||||
if ($size === null)
|
||||
{
|
||||
@ -331,7 +344,7 @@ class local implements adapter_interface, stream_interface
|
||||
*/
|
||||
public function file_mimetype($path)
|
||||
{
|
||||
return ['mimetype' => $this->mimetype_guesser->guess($this->root_path . $this->get_subfolder($path) . $path)];
|
||||
return ['mimetype' => $this->mimetype_guesser->guess($this->root_path . $this->get_filepath($path))];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -343,12 +356,12 @@ class local implements adapter_interface, stream_interface
|
||||
*/
|
||||
protected function image_dimensions($path)
|
||||
{
|
||||
$size = $this->imagesize->getImageSize($this->root_path . $this->get_subfolder($path) . $path);
|
||||
$size = $this->imagesize->getImageSize($this->root_path . $this->get_filepath($path));
|
||||
|
||||
// For not supported types like swf
|
||||
if ($size === false)
|
||||
{
|
||||
$imsize = getimagesize($this->root_path . $this->get_subfolder($path) . $path);
|
||||
$imsize = getimagesize($this->root_path . $this->get_filepath($path));
|
||||
$size = ['width' => $imsize[0], 'height' => $imsize[1]];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user