Skip to content

Instantly share code, notes, and snippets.

@bitsmanent
Last active November 10, 2018 20:41
Show Gist options
  • Save bitsmanent/b8d4f645702b7bb1a8fa to your computer and use it in GitHub Desktop.
Save bitsmanent/b8d4f645702b7bb1a8fa to your computer and use it in GitHub Desktop.
Transform $_POST and $_FILES into a better format to deal with
function prepare_form() {
$key = key($_FILES);
if(!$key)
return;
$files = @$_FILES[$key];
if(@$_POST[$key]) {
$files = array_merge($files, $_POST[$key]);
unset($_POST[$key]);
}
$ret = [];
if(is_array($files['name'])) {
foreach($files as $k => $unused) {
foreach($files[$k] as $i => $v) {
if(!isset($ret[$i]))
$ret[$i] = [];
$ret[$i][$k] = $v;
}
}
}
else
$ret = [$files];
$_FILES = $ret;
}
@bitsmanent
Copy link
Author

What about including it on https://github.com/clamiax/tinycore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment