Last active
November 10, 2018 20:41
-
-
Save bitsmanent/b8d4f645702b7bb1a8fa to your computer and use it in GitHub Desktop.
Transform $_POST and $_FILES into a better format to deal with
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about including it on https://github.com/clamiax/tinycore?