note 98076 added to features.file-upload.post-method

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
As daevid noticed, the structure of $_FILES array is rather strange. Here is the way to fix it:

<?php

function sortFiles() {
	
	$sortedFiles = array();
	foreach ($_FILES as $key => $file)
	{
		$sortedFiles[$key] = array();
		if (is_int($file['error']))
		{
			$sortedFiles[$key] = $file;
		}
		elseif (is_array($file['error']))
		{
			$sortedFiles[$key] = array();
			$params = array('error', 'size', 'name', 'tmp_name', 'type');
			foreach ($params as $param)
			{
				subSortFiles($file[$param], $sortedFiles[$key], $param);
			}
		}
	}
	$_FILES = $sortedFiles;

}

function subSortFiles(&$arr, &$mask, $param)
{
	foreach ($arr as $key => $value)
	{
		if (!is_array($mask[$key]))
		{
			$mask[$key] = array();
		}
		if (is_array($value))
		{
			subFixFiles($value, $mask[$key], $param);
		}
		else
		{
			$mask[$key][$param] = $value;
		}
	}
}

?>
----
Server IP: 69.147.83.197
Probable Submitter: 85.140.23.56
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.post-method.php
Edit        -- https://master.php.net/note/edit/98076
Del: integrated  -- https://master.php.net/note/delete/98076/integrated
Del: useless     -- https://master.php.net/note/delete/98076/useless
Del: bad code    -- https://master.php.net/note/delete/98076/bad+code
Del: spam        -- https://master.php.net/note/delete/98076/spam
Del: non-english -- https://master.php.net/note/delete/98076/non-english
Del: in docs     -- https://master.php.net/note/delete/98076/in+docs
Del: other reasons-- https://master.php.net/note/delete/98076
Reject      -- https://master.php.net/note/reject/98076
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.