function _filefield_source_remote_parse_header in FileField Sources 7
Same name and namespace in other branches
- 6 sources/remote.inc \_filefield_source_remote_parse_header()
Parse cURL header and record the filename specified in Content-Disposition.
1 string reference to '_filefield_source_remote_parse_header'
- filefield_source_remote_value in sources/
remote.inc - A #filefield_value_callback function.
File
- sources/
remote.inc, line 273 - A FileField extension to allow referencing of existing files.
Code
function _filefield_source_remote_parse_header($ch, $header) {
if (preg_match('/Content-Disposition:.*?filename="(.+?)"/i', $header, $matches)) {
// Content-Disposition: attachment; filename="FILE NAME HERE"
_filefield_source_remote_filename($matches[1]);
}
elseif (preg_match('/Content-Disposition:.*?filename=([^; ]+)/i', $header, $matches)) {
// Content-Disposition: attachment; filename=file.ext
$uri = trim($matches[1]);
_filefield_source_remote_filename($uri);
}
elseif (preg_match('/Content-Type:[ ]*([a-z0-9_\\-]+\\/[a-z0-9_\\-]+)/i', $header, $matches)) {
$mime_type = $matches[1];
_filefield_source_remote_mime_extension($mime_type);
}
// This is required by cURL.
return strlen($header);
}