Last active
December 27, 2015 13:48
-
-
Save mvmaasakkers/7335471 to your computer and use it in GitHub Desktop.
Fix for content-disposition issues on multipart forms via php://input (for instance PUT requests)
This file contains 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
<?php | |
function getPostfieldsFromInput() { | |
$ct = $_SERVER['CONTENT_TYPE']; | |
$position = stripos($ct, "multipart/form-data;"); | |
$input = file_get_contents("php://input"); | |
$postVars = array(); | |
if($position !== false) { | |
$exp = explode("boundary=", $ct); | |
if(isset($exp[1])) { | |
$boundary = trim($exp[1]); | |
$variables = explode("--".$boundary, $input); | |
foreach($variables as $var) { | |
if(trim($var) != "" && trim($var) != "--") { | |
preg_match('/Content-Disposition: form-data; name="([^\"]*)"(.*)/si', $var, $result); | |
$postVars[trim($result[1])] = trim($resulta[2]); | |
} | |
} | |
} | |
} else { | |
parse_str($input, $postVars); | |
} | |
return $postVars; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment