24 class File extends \SplFileInfo
36 if ($checkPath && !is_file($path)) {
40 parent::__construct($path);
61 return $guesser->guess($type);
79 return $guesser->guess($this->getPathname());
92 public function move($directory, $name =
null)
96 if (!@rename($this->getPathname(), $target)) {
97 $error = error_get_last();
98 throw new FileException(sprintf(
'Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error[
'message'])));
101 @chmod($target, 0666 & ~umask());
108 if (!is_dir($directory)) {
109 if (
false === @mkdir($directory, 0777,
true) && !is_dir($directory)) {
110 throw new FileException(sprintf(
'Unable to create the "%s" directory', $directory));
112 } elseif (!is_writable($directory)) {
113 throw new FileException(sprintf(
'Unable to write in the "%s" directory', $directory));
116 $target = rtrim($directory,
'/\\').DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->
getName($name));
118 return new self($target,
false);
130 $originalName = str_replace(
'\\',
'/', $name);
131 $pos = strrpos($originalName,
'/');
132 $originalName =
false === $pos ? $originalName : substr($originalName, $pos + 1);
134 return $originalName;