Check file header to get correct filename if file is at a URL like http://example.com/get_file/23

This is inspired by filefield_sources module http://cgit.drupalcode.org/filefield_sources/tree/sources/remote.inc?h=7... but also checks for location.

The updated behavior keeps the http://example.com/get_file/23 as the URI but gets the correct filename and filemime.

Comments

topicus’s picture

There is an small issue with this patch that is causing some warnings:

This retrieve the file extension instead of the mime type.

 $file->filemime = _remote_file_source_mime_extension($mime_type);

I've changed this by:

 $file->filemime = $mime_type;
topicus’s picture

StatusFileSize
new4.19 KB
topicus’s picture

StatusFileSize
new4.21 KB
dafeder’s picture

I've moved and expanded some of this logic into separate functions and made some things more consistent, to remove use of drupal_http_request() completely.