public isValidName ( string $name ) : boolean | ||
$name | string | |
리턴 | boolean |
public function isValidName(string $name) : bool
{
if ($name === '.' || $name === '..') {
// Web browsers will probably handle relative paths stupidly,
// so let's avoid the hassle before it ever becomes one
return false;
}
if (\strpos($name, '/') !== false || \strpos($name, '?') !== false || \strpos($name, '&') !== false) {
// Once again, this is just looking to create a headache down the road.
return false;
}
if (Util::stringLength($name) < 1) {
return false;
} elseif (Util::stringLength($name) === 1) {
// Single byte directory/file names must be a printable ASCII character.
// Preferably: one that is legible and semantically meaningful.
return 0 < \preg_match('#^[A-Za-z0-9\\-_~=\\+]$#', $name[0]);
}
// No other rules yet.
return true;
}
/** * Create a new directory for file uploads * * @param int $directoryId * @param string $cabin * @param array $post * @return array */ protected function createDir($directoryId = null, string $cabin = '', array $post = []) : array { if (!\array_key_exists('directory', $post)) { return ['status' => 'ERROR', 'message' => 'Directory names cannot be empty']; } if (!$this->files->isValidName($post['directory'])) { return ['status' => 'ERROR', 'message' => 'Invalid directory name']; } if ($this->files->dirExists($directoryId, $cabin, $post['directory'])) { return ['status' => 'ERROR', 'message' => 'This directory already exists']; } if ($this->files->createDirectory($directoryId, $cabin, $post['directory'])) { return ['status' => 'SUCCESS', 'message' => 'This directory has been created sucessfully']; } return ['status' => 'UNKNOWN', 'message' => 'An unknown error has occurred.']; }