diff options
author | Max Kostikov <max@kostikov.co> | 2018-11-08 22:43:17 +0100 |
---|---|---|
committer | Max Kostikov <max@kostikov.co> | 2018-11-08 22:43:17 +0100 |
commit | 098ec1abb46c70774a6c239f59c77df4b6437335 (patch) | |
tree | 538f4f3e2149eb533be04531695f8bc1a89f3a1c | |
parent | 17cf824545a4e059183f0a43af9692a90100c55a (diff) | |
download | volse-hubzilla-098ec1abb46c70774a6c239f59c77df4b6437335.tar.gz volse-hubzilla-098ec1abb46c70774a6c239f59c77df4b6437335.tar.bz2 volse-hubzilla-098ec1abb46c70774a6c239f59c77df4b6437335.zip |
remove image type double guess by checking HTTP headers
-rw-r--r-- | include/photo/photo_driver.php | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 911b97ade..12465c794 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -485,11 +485,11 @@ function guess_image_type($filename, $headers = '') { $h = explode("\n",$headers); foreach ($h as $l) { list($k,$v) = array_map("trim", explode(":", trim($l), 2)); - $hdrs[$k] = $v; + $hdrs[strtolower($k)] = $v; } logger('Curl headers: '.var_export($hdrs, true), LOGGER_DEBUG); - if (array_key_exists('Content-Type', $hdrs)) - $type = $hdrs['Content-Type']; + if (array_key_exists('content-type', $hdrs)) + $type = $hdrs['content-type']; } if (is_null($type)){ @@ -637,16 +637,8 @@ function import_xchan_photo($photo,$xchan,$thing = false,$force = false) { $type = guess_image_type($photo, $result['header']); $modified = gmdate('Y-m-d H:i:s', (preg_match('/last-modified: (.+) \S+/i', $result['header'], $o) ? strtotime($o[1] . 'Z') : time())); - $h = explode("\n",$result['header']); - if($h) { - foreach($h as $hl) { - if(stristr($hl,'content-type:')) { - if(! stristr($hl,'image/')) { - $photo_failure = true; - } - } - } - } + if(is_null($type)) + $photo_failure = true; } elseif($result['return_code'] = 304) { $photo = z_root() . '/photo/' . $hash . '-4'; @@ -744,16 +736,8 @@ function import_channel_photo_from_url($photo,$aid,$uid) { $img_str = $result['body']; $type = guess_image_type($photo, $result['header']); - $h = explode("\n",$result['header']); - if($h) { - foreach($h as $hl) { - if(stristr($hl,'content-type:')) { - if(! stristr($hl,'image/')) { - $photo_failure = true; - } - } - } - } + if(is_null($type)) + $photo_failure = true; } } else { |