本文整理汇总了PHP中SplFileInfo::getSanitizedName方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getSanitizedName方法的具体用法?PHP SplFileInfo::getSanitizedName怎么用?PHP SplFileInfo::getSanitizedName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::getSanitizedName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preUpload
/**
* @ORM\PreFlush()
*/
public function preUpload()
{
if ($this->file) {
if ($this->file instanceof FileUpload) {
$basename = $this->file->getSanitizedName();
$basename = $this->suggestName($this->getFilePath(), $basename);
$this->setName($basename);
} else {
$basename = trim(Strings::webalize($this->file->getBasename(), '.', FALSE), '.-');
$basename = $this->suggestName(dirname($this->file->getPathname()), $basename);
$this->setName($basename);
}
if ($this->_oldPath && $this->_oldPath !== $this->path) {
@unlink($this->getFilePathBy($this->_oldProtected, $this->_oldPath));
}
if ($this->file instanceof FileUpload) {
$this->file->move($this->getFilePath());
} else {
copy($this->file->getPathname(), $this->getFilePath());
}
return $this->file = NULL;
}
if (($this->_oldPath || $this->_oldProtected !== NULL) && ($this->_oldPath != $this->path || $this->_oldProtected != $this->protected)) {
$oldFilePath = $this->getFilePathBy($this->_oldProtected !== NULL ? $this->_oldProtected : $this->protected, $this->_oldPath ?: $this->path);
if (file_exists($oldFilePath)) {
rename($oldFilePath, $this->getFilePath());
}
}
}
示例2: preFlush
/**
* @internal
*
* @ORM\PreFlush()
*/
public function preFlush()
{
if ($this->removed) {
return;
}
if ($this->file) {
if ($this->file instanceof FileUpload) {
$basename = $this->file->getSanitizedName();
$basename = $this->suggestName($basename);
$this->setName($basename);
} else {
$basename = trim(Strings::webalize($this->file->getBasename(), '.', false), '.-');
$basename = $this->suggestName($basename);
$this->setName($basename);
}
if ($this->oldPath && $this->oldPath !== $this->path) {
$filePath = $this->getFilePathBy($this->oldProtected, $this->oldPath);
if (!is_file($filePath)) {
throw new RemoveFileException(sprintf('File \'%s\' does not exist.', $filePath));
}
unlink($filePath);
if (is_file($filePath)) {
throw new RemoveFileException(sprintf('File \'%s\' cannot be removed. Check access rights.', $filePath));
}
}
if ($this->file instanceof FileUpload) {
try {
$filePath = $this->getFilePath();
$this->file->move($filePath);
} catch (\Nette\InvalidStateException $e) {
throw new UploadFileException();
}
if (!is_file($filePath)) {
throw new RemoveFileException(sprintf('File \'%s\' does not exist.', $filePath));
}
} else {
$oldFilePath = $this->file->getPathname();
$filePath = $this->getFilePath();
if (!is_file($oldFilePath)) {
throw new RenameFileException(sprintf('File \'%s\' does not exist.', $oldFilePath));
}
if (is_file($filePath)) {
throw new RenameFileException(sprintf('File \'%s\' already exists.', $filePath));
}
copy($oldFilePath, $filePath);
if (!is_file($filePath)) {
throw new RenameFileException(sprintf('File \'%s\' does not exist.', $filePath));
}
}
$this->size = filesize($this->getFilePath());
$this->mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->getFilePath());
return $this->file = null;
}
if (($this->oldPath || $this->oldProtected !== null) && ($this->oldPath !== $this->path || $this->oldProtected !== $this->protected)) {
$oldFilePath = $this->getFilePathBy($this->oldProtected !== null ? $this->oldProtected : $this->protected, $this->oldPath !== null ? $this->oldPath : $this->path);
$filePath = $this->getFilePath();
if (!is_file($oldFilePath)) {
throw new RenameFileException(sprintf('File \'%s\' does not exist.', $oldFilePath));
}
if (is_file($filePath)) {
throw new RenameFileException(sprintf('File \'%s\' already exists.', $filePath));
}
rename($oldFilePath, $filePath);
if (is_file($oldFilePath)) {
throw new RenameFileException(sprintf('File \'%s\' already exists.', $oldFilePath));
}
if (!is_file($filePath)) {
throw new RenameFileException(sprintf('File \'%s\' does not exist.', $filePath));
}
}
}