|
@@ -3,6 +3,7 @@
|
|
|
namespace Symfony\Component\HttpFoundation;
|
|
|
|
|
|
use Symfony\Component\HttpFoundation\SessionStorage\NativeSessionStorage;
|
|
|
+use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|
|
|
|
|
/*
|
|
|
* This file is part of the Symfony package.
|
|
@@ -846,50 +847,53 @@ class Request
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Converts uploaded file array to a format following the $_GET and $POST naming convention.
|
|
|
+ * Converts uploaded files to UploadedFile instances.
|
|
|
*
|
|
|
- * It's safe to pass an already converted array, in which case this method just returns the original array unmodified.
|
|
|
+ * @param array $files A (multi-dimensional) array of uploaded file information
|
|
|
*
|
|
|
- * @param array $taintedFiles An array representing uploaded file information
|
|
|
- *
|
|
|
- * @return array An array of re-ordered uploaded file information
|
|
|
+ * @return array A (multi-dimensional) array of UploadedFile instances
|
|
|
*/
|
|
|
- protected function convertFileInformation(array $taintedFiles)
|
|
|
+ protected function convertFileInformation(array $files)
|
|
|
{
|
|
|
- $files = array();
|
|
|
- foreach ($taintedFiles as $key => $data) {
|
|
|
- $files[$key] = $this->fixPhpFilesArray($data);
|
|
|
+ $fixedFiles = array();
|
|
|
+
|
|
|
+ foreach ($files as $key => $data) {
|
|
|
+ $fixedFiles[$key] = $this->fixPhpFilesArray($data);
|
|
|
}
|
|
|
|
|
|
- return $files;
|
|
|
- }
|
|
|
+ $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
|
|
|
+ foreach ($fixedFiles as $key => $data) {
|
|
|
+ if (is_array($data)) {
|
|
|
+ $keys = array_keys($data);
|
|
|
+ sort($keys);
|
|
|
|
|
|
- protected function initializeHeaders()
|
|
|
- {
|
|
|
- $headers = array();
|
|
|
- foreach ($this->server->all() as $key => $value) {
|
|
|
- if ('http_' === strtolower(substr($key, 0, 5))) {
|
|
|
- $headers[substr($key, 5)] = $value;
|
|
|
+ if ($keys == $fileKeys) {
|
|
|
+ $fixedFiles[$key] = new UploadedFile($data['tmp_name'], $data['name'], $data['type'], $data['size'], $data['error']);
|
|
|
+ } else {
|
|
|
+ $fixedFiles[$key] = $this->convertFileInformation($data);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return $headers;
|
|
|
+ return $fixedFiles;
|
|
|
}
|
|
|
|
|
|
- static protected function initializeFormats()
|
|
|
- {
|
|
|
- static::$formats = array(
|
|
|
- 'txt' => 'text/plain',
|
|
|
- 'js' => array('application/javascript', 'application/x-javascript', 'text/javascript'),
|
|
|
- 'css' => 'text/css',
|
|
|
- 'json' => array('application/json', 'application/x-json'),
|
|
|
- 'xml' => array('text/xml', 'application/xml', 'application/x-xml'),
|
|
|
- 'rdf' => 'application/rdf+xml',
|
|
|
- 'atom' => 'application/atom+xml',
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- static protected function fixPhpFilesArray($data)
|
|
|
+ /**
|
|
|
+ * 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.
|
|
|
+ *
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ protected function fixPhpFilesArray($data)
|
|
|
{
|
|
|
$fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
|
|
|
$keys = array_keys($data);
|
|
@@ -904,7 +908,7 @@ class Request
|
|
|
unset($files[$k]);
|
|
|
}
|
|
|
foreach (array_keys($data['name']) as $key) {
|
|
|
- $files[$key] = self::fixPhpFilesArray(array(
|
|
|
+ $files[$key] = $this->fixPhpFilesArray(array(
|
|
|
'error' => $data['error'][$key],
|
|
|
'name' => $data['name'][$key],
|
|
|
'type' => $data['type'][$key],
|
|
@@ -915,4 +919,29 @@ class Request
|
|
|
|
|
|
return $files;
|
|
|
}
|
|
|
+
|
|
|
+ protected function initializeHeaders()
|
|
|
+ {
|
|
|
+ $headers = array();
|
|
|
+ foreach ($this->server->all() as $key => $value) {
|
|
|
+ if ('http_' === strtolower(substr($key, 0, 5))) {
|
|
|
+ $headers[substr($key, 5)] = $value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $headers;
|
|
|
+ }
|
|
|
+
|
|
|
+ static protected function initializeFormats()
|
|
|
+ {
|
|
|
+ static::$formats = array(
|
|
|
+ 'txt' => 'text/plain',
|
|
|
+ 'js' => array('application/javascript', 'application/x-javascript', 'text/javascript'),
|
|
|
+ 'css' => 'text/css',
|
|
|
+ 'json' => array('application/json', 'application/x-json'),
|
|
|
+ 'xml' => array('text/xml', 'application/xml', 'application/x-xml'),
|
|
|
+ 'rdf' => 'application/rdf+xml',
|
|
|
+ 'atom' => 'application/atom+xml',
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|