Skip to content

Instantly share code, notes, and snippets.

@mvmaasakkers
Last active December 27, 2015 13:48
Show Gist options
  • Save mvmaasakkers/7335471 to your computer and use it in GitHub Desktop.
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)
<?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