@@ 1209-1227 (lines=19) @@ | ||
1206 | * Unfortunately, prior to PHP 5.3 - it's only available as a PECL extension and the |
|
1207 | * more convenient FILEINFO_MIME_TYPE flag doesn't exist. |
|
1208 | */ |
|
1209 | if (function_exists('finfo_file')) |
|
1210 | { |
|
1211 | $finfo = @finfo_open(FILEINFO_MIME); |
|
1212 | if (is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system |
|
1213 | { |
|
1214 | $mime = @finfo_file($finfo, $file['tmp_name']); |
|
1215 | finfo_close($finfo); |
|
1216 | ||
1217 | /* According to the comments section of the PHP manual page, |
|
1218 | * it is possible that this function returns an empty string |
|
1219 | * for some files (e.g. if they don't exist in the magic MIME database) |
|
1220 | */ |
|
1221 | if (is_string($mime) && preg_match($regexp, $mime, $matches)) |
|
1222 | { |
|
1223 | $this->file_type = $matches[1]; |
|
1224 | return; |
|
1225 | } |
|
1226 | } |
|
1227 | } |
|
1228 | ||
1229 | /* This is an ugly hack, but UNIX-type systems provide a "native" way to detect the file type, |
|
1230 | * which is still more secure than depending on the value of $_FILES[$field]['type'], and as it |
|
@@ 1278-1291 (lines=14) @@ | ||
1275 | if (function_usable('popen')) |
|
1276 | { |
|
1277 | $proc = @popen($cmd, 'r'); |
|
1278 | if (is_resource($proc)) |
|
1279 | { |
|
1280 | $mime = @fread($proc, 512); |
|
1281 | @pclose($proc); |
|
1282 | if ($mime !== FALSE) |
|
1283 | { |
|
1284 | $mime = explode("\n", trim($mime)); |
|
1285 | if (preg_match($regexp, $mime[(count($mime) - 1)], $matches)) |
|
1286 | { |
|
1287 | $this->file_type = $matches[1]; |
|
1288 | return; |
|
1289 | } |
|
1290 | } |
|
1291 | } |
|
1292 | } |
|
1293 | } |
|
1294 |