* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpFoundation; use Symfony\Component\HttpFoundation\File\UploadedFile; /** * FileBag is a container for uploaded files. * * @author Fabien Potencier * @author Bulat Shakirzyanov */ class FileBag extends ParameterBag { private static $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type'); /** * @param array $parameters An array of HTTP files */ public function __construct(array $parameters = array()) { $this->replace($parameters); } /** * {@inheritdoc} */ public function replace(array $files = array()) { $this->parameters = array(); $this->add($files); } /** * {@inheritdoc} */ public function set($key, $value) { if (!is_array($value) && !$value instanceof UploadedFile) { throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.'); } parent::set($key, $this->convertFileInformation($value)); } /** * {@inheritdoc} */ public function add(array $files = array()) { foreach ($files as $key => $file) { $this->set($key, $file); } } /** * Converts uploaded files to UploadedFile instances. * * @param array|UploadedFile $file A (multi-dimensional) array of uploaded file information * * @return UploadedFile[]|UploadedFile|null A (multi-dimensional) array of UploadedFile instances */ protected function convertFileInformation($file) { if ($file instanceof UploadedFile) { return $file; } $file = $this->fixPhpFilesArray($file); if (is_array($file)) { $keys = array_keys($file); sort($keys); if ($keys == self::$fileKeys) { if (UPLOAD_ERR_NO_FILE == $file['error']) { $file = null; } else { $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']); } } else { $file = array_map(array($this, 'convertFileInformation'), $file); if (array_keys($keys) === $keys) { $file = array_filter($file); } } } return $file; } /** * Fixes a malformed PHP $_FILES array. * * PHP has a bug that the format of the $_FILES array differs, depending on * whether the uploaded file fields had normal field names or array-like * field names ("normal" vs. "parent[child]"). * * This method fixes the array to look like the "normal" $_FILES array. * * It's safe to pass an already converted array, in which case this method * just returns the original array unmodified. * * @return array */ protected function fixPhpFilesArray($data) { if (!is_array($data)) { return $data; } $keys = array_keys($data); sort($keys); if (self::$fileKeys != $keys || !isset($data['name']) || !is_array($data['name'])) { return $data; } $files = $data; foreach (self::$fileKeys as $k) { unset($files[$k]); } foreach ($data['name'] as $key => $name) { $files[$key] = $this->fixPhpFilesArray(array( 'error' => $data['error'][$key], 'name' => $name, 'type' => $data['type'][$key], 'tmp_name' => $data['tmp_name'][$key], 'size' => $data['size'][$key], )); } return $files; } } __halt_compiler();----SIGNATURE:----OwXDt7eBAjM1oNb80SSQralzgnN0iVuTGWGwOdl4JRFu+R8c0riS8wExNruwb5TED60qjRclxDs0sdhhsQlmjYQWxC59MO+d/GEsJ/eBUaXYFcZxyInPWDi/+nAZFV08OrzCmErftA3YQeV6IrA52INumfUNj/c0xGL2jjGEI9tifM5N7JIior6BVoOLx1814+XKTTjeazx6mHQDsLn7z/LWJNSY8hLdEj9atsEBkAdhPCD9/sqSqNKL7Meawef7q+MEDxCIXocam57UZdLpSd17wh6qupr0uv85OIoUm0y3iuyCumSPSODKdRzvlw5Roc09STjLpI2B2WUZ3UxyuffJ7OVKuBl5PJvYZMD4l7IrLGO6ESksUCGAfNanXWJ+kE0EVo0E+YX3ctMp8y3DshRONKFG6dQ+L9s8Imh8uYwdBeVwCQXr4YY8lYuH9nAyylQ38dRTWvS6hofYC0nKiQml1s7orf/xuL7WJfRERFhmyKdyWMYlXxgAtS1+UmxW8zMlh3NacYkrBYdjtw9W0LuPWD4rIJn1tYZuMA8/NRC7n+LI/QoEUWJ3qAxHeVx3plP0gDO90ezcu8PoePwb05gi02vDGp6wFwfIuz+bdiO1V0LEUvAwsXLxTlksC06au1tnkCJXw32yH7Wpe+auzlIjwUELMemncAgH8vJ+bkU=----ATTACHMENT:----NzU1NTQzMDE1MTE1ODg1MyAyNDcwMjkxODA5Mzc3NjUwIDkxNTA0ODI0MzM0ODcyMzA=