Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
File.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpFoundation\File;
013
014 use Symfony\Component\HttpFoundation\File\Exception\FileException;
015 use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
016 use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
017 use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
018
019 /**
020 * A file in the file system.
021 *
022 * @author Bernhard Schussek <bschussek@gmail.com>
023 */
024 class File extends \SplFileInfo
025 {
026 /**
027 * Constructs a new file from the given path.
028 *
029 * @param string $path The path to the file
030 * @param bool $checkPath Whether to check the path or not
031 *
032 * @throws FileNotFoundException If the given path is not a file
033 */
034 public function __construct($path, $checkPath = true)
035 {
036 if ($checkPath && !is_file($path)) {
037 throw new FileNotFoundException($path);
038 }
039
040 parent::__construct($path);
041 }
042
043 /**
044 * Returns the extension based on the mime type.
045 *
046 * If the mime type is unknown, returns null.
047 *
048 * This method uses the mime type as guessed by getMimeType()
049 * to guess the file extension.
050 *
051 * @return string|null The guessed extension or null if it cannot be guessed
052 *
053 * @see ExtensionGuesser
054 * @see getMimeType()
055 */
056 public function guessExtension()
057 {
058 $type = $this->getMimeType();
059 $guesser = ExtensionGuesser::getInstance();
060
061 return $guesser->guess($type);
062 }
063
064 /**
065 * Returns the mime type of the file.
066 *
067 * The mime type is guessed using a MimeTypeGuesser instance, which uses finfo(),
068 * mime_content_type() and the system binary "file" (in this order), depending on
069 * which of those are available.
070 *
071 * @return string|null The guessed mime type (e.g. "application/pdf")
072 *
073 * @see MimeTypeGuesser
074 */
075 public function getMimeType()
076 {
077 $guesser = MimeTypeGuesser::getInstance();
078
079 return $guesser->guess($this->getPathname());
080 }
081
082 /**
083 * Moves the file to a new location.
084 *
085 * @param string $directory The destination folder
086 * @param string $name The new file name
087 *
088 * @return File A File object representing the new file
089 *
090 * @throws FileException if the target file could not be created
091 */
092 public function move($directory, $name = null)
093 {
094 $target = $this->getTargetFile($directory, $name);
095
096 if (!@rename($this->getPathname(), $target)) {
097 $error = error_get_last();
098 throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message'])));
099 }
100
101 @chmod($target, 0666 & ~umask());
102
103 return $target;
104 }
105
106 protected function getTargetFile($directory, $name = null)
107 {
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));
111 }
112 } elseif (!is_writable($directory)) {
113 throw new FileException(sprintf('Unable to write in the "%s" directory', $directory));
114 }
115
116 $target = rtrim($directory, '/\\').DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name));
117
118 return new self($target, false);
119 }
120
121 /**
122 * Returns locale independent base name of the given path.
123 *
124 * @param string $name The new file name
125 *
126 * @return string containing
127 */
128 protected function getName($name)
129 {
130 $originalName = str_replace('\\', '/', $name);
131 $pos = strrpos($originalName, '/');
132 $originalName = false === $pos ? $originalName : substr($originalName, $pos + 1);
133
134 return $originalName;
135 }
136 }
137