Merge pull request #425 from DakuTree/patch-headerfix
Fix for #423 - Check for lowercase header if camelcase header doesn't exist
This commit is contained in:
commit
8d75968ab0
2 changed files with 21 additions and 2 deletions
|
@ -935,6 +935,23 @@ if (!function_exists('http_parse_headers')) { #http://www.php.net/manual/en/func
|
|||
}
|
||||
}
|
||||
|
||||
function findHeader ($headers, $name){
|
||||
//HTTP Headers can sometimes be lowercase which will cause issues.
|
||||
//In cases like these, we need to make sure to check for them if the camelcase version does not exist.
|
||||
$header = FALSE;
|
||||
|
||||
if(array_key_exists($name, $headers)){
|
||||
$header = $headers[$name];
|
||||
}else{
|
||||
$headers = array_change_key_case($headers);
|
||||
if(array_key_exists(strtolower($name), $headers)){
|
||||
$header = $headers[strtolower($name)];
|
||||
}
|
||||
}
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
$_included = array();
|
||||
/**
|
||||
* Get the active contents of a .php file
|
||||
|
|
|
@ -344,7 +344,9 @@ class Upload extends Extension {
|
|||
$tmp_filename = tempnam(ini_get('upload_tmp_dir'), "shimmie_transload");
|
||||
|
||||
$headers = transload($url, $tmp_filename);
|
||||
$h_filename = (isset($headers['Content-Disposition']) ? preg_replace('/^.*filename="([^ ]+)"/i', '$1', $headers['Content-Disposition']) : null);
|
||||
|
||||
$s_filename = findHeader($headers, 'Content-Disposition');
|
||||
$h_filename = ($s_filename ? preg_replace('/^.*filename="([^ ]+)"/i', '$1', $s_filename) : null);
|
||||
$filename = $h_filename ?: basename($url);
|
||||
|
||||
if(!$headers) {
|
||||
|
@ -362,7 +364,7 @@ class Upload extends Extension {
|
|||
$pathinfo = pathinfo($url);
|
||||
$metadata = array();
|
||||
$metadata['filename'] = $filename;
|
||||
$metadata['extension'] = getExtension($headers['Content-Type']) ?: $pathinfo['extension'];
|
||||
$metadata['extension'] = getExtension(findHeader($headers, 'Content-Type')) ?: $pathinfo['extension'];
|
||||
$metadata['tags'] = $tags;
|
||||
$metadata['source'] = (($url == $source) && !$config->get_bool('upload_tlsource') ? "" : $source);
|
||||
|
||||
|
|
Reference in a new issue