public function moveTo($dst, $allowedExtensions = 'jpg,jpeg,png,gif,doc,xls,pdf,zip')
{
$extension = pathinfo($dst, PATHINFO_EXTENSION);
if ($extension) {
$extension = ',' . $extension . ',';
if (is_string($allowedExtensions)) {
$allowedExtensions = ',' . str_replace(' ', '', $allowedExtensions) . ',';
$allowedExtensions = str_replace(',.', ',', $allowedExtensions);
if (!Text::contains($allowedExtensions, $extension, true)) {
throw new FileException('`:extension` file type is not allowed upload', ['extension' => $extension]);
}
}
if (is_string(self::$_alwaysRejectedExtensions)) {
$alwaysRejectedExtensions = ',' . str_replace(' ', '', self::$_alwaysRejectedExtensions) . ',';
$alwaysRejectedExtensions = str_replace(',.', ',', $alwaysRejectedExtensions);
if (Text::contains($alwaysRejectedExtensions, $extension, true)) {
throw new FileException('`:extension` file types is not allowed upload always', ['extensions' => self::$_alwaysRejectedExtensions]);
}
}
}
if ($this->_file['error'] !== UPLOAD_ERR_OK) {
throw new FileException('error code of upload file is not UPLOAD_ERR_OK: :error', ['error' => $this->_file['error']]);
}
if ($this->filesystem->fileExists($dst)) {
throw new FileException('`:file` file already exists', ['file' => $dst]);
}
$this->filesystem->dirCreate(dirname($dst));
if (!move_uploaded_file($this->_file['tmp_name'], $this->alias->resolve($dst))) {
throw new FileException('move_uploaded_file to `:dst` failed: :last_error_message', ['dst' => $dst]);
}
if (!chmod($this->alias->resolve($dst), 0644)) {
throw new FileException('chmod `:dst` destination failed: :last_error_message', ['dst' => $dst]);
}
}