Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
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 |
FileBag.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;
013
014 use Symfony\Component\HttpFoundation\File\UploadedFile;
015
016 /**
017 * FileBag is a container for uploaded files.
018 *
019 * @author Fabien Potencier <fabien@symfony.com>
020 * @author Bulat Shakirzyanov <mallluhuct@gmail.com>
021 *
022 * @api
023 */
024 class FileBag extends ParameterBag
025 {
026 private static $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
027
028 /**
029 * Constructor.
030 *
031 * @param array $parameters An array of HTTP files
032 *
033 * @api
034 */
035 public function __construct(array $parameters = array())
036 {
037 $this->replace($parameters);
038 }
039
040 /**
041 * {@inheritdoc}
042 *
043 * @api
044 */
045 public function replace(array $files = array())
046 {
047 $this->parameters = array();
048 $this->add($files);
049 }
050
051 /**
052 * {@inheritdoc}
053 *
054 * @api
055 */
056 public function set($key, $value)
057 {
058 if (!is_array($value) && !$value instanceof UploadedFile) {
059 throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.');
060 }
061
062 parent::set($key, $this->convertFileInformation($value));
063 }
064
065 /**
066 * {@inheritdoc}
067 *
068 * @api
069 */
070 public function add(array $files = array())
071 {
072 foreach ($files as $key => $file) {
073 $this->set($key, $file);
074 }
075 }
076
077 /**
078 * Converts uploaded files to UploadedFile instances.
079 *
080 * @param array|UploadedFile $file A (multi-dimensional) array of uploaded file information
081 *
082 * @return array A (multi-dimensional) array of UploadedFile instances
083 */
084 protected function convertFileInformation($file)
085 {
086 if ($file instanceof UploadedFile) {
087 return $file;
088 }
089
090 $file = $this->fixPhpFilesArray($file);
091 if (is_array($file)) {
092 $keys = array_keys($file);
093 sort($keys);
094
095 if ($keys == self::$fileKeys) {
096 if (UPLOAD_ERR_NO_FILE == $file['error']) {
097 $file = null;
098 } else {
099 $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
100 }
101 } else {
102 $file = array_map(array($this, 'convertFileInformation'), $file);
103 }
104 }
105
106 return $file;
107 }
108
109 /**
110 * Fixes a malformed PHP $_FILES array.
111 *
112 * PHP has a bug that the format of the $_FILES array differs, depending on
113 * whether the uploaded file fields had normal field names or array-like
114 * field names ("normal" vs. "parent[child]").
115 *
116 * This method fixes the array to look like the "normal" $_FILES array.
117 *
118 * It's safe to pass an already converted array, in which case this method
119 * just returns the original array unmodified.
120 *
121 * @param array $data
122 *
123 * @return array
124 */
125 protected function fixPhpFilesArray($data)
126 {
127 if (!is_array($data)) {
128 return $data;
129 }
130
131 $keys = array_keys($data);
132 sort($keys);
133
134 if (self::$fileKeys != $keys || !isset($data['name']) || !is_array($data['name'])) {
135 return $data;
136 }
137
138 $files = $data;
139 foreach (self::$fileKeys as $k) {
140 unset($files[$k]);
141 }
142
143 foreach (array_keys($data['name']) as $key) {
144 $files[$key] = $this->fixPhpFilesArray(array(
145 'error' => $data['error'][$key],
146 'name' => $data['name'][$key],
147 'type' => $data['type'][$key],
148 'tmp_name' => $data['tmp_name'][$key],
149 'size' => $data['size'][$key],
150 ));
151 }
152
153 return $files;
154 }
155 }
156