The views module provides a views field for file extension (.jpg, .pdf, etc) but not a filter. Could we please have a filter so that we can build views showing only PDFs, for example?

The file type flter (provided by file entity module) is not sufficient because if file entity module is added to a site after there are already files in the system, there is no type defined for any of the files that predate the file entity module.

An alternative might be to provide a batch operation in file_entity() that would update the data for all the older files. See #1977662: On fresh install, existing files are assigned to 'undefined' file type

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jenlampton’s picture

Project: File Entity (fieldable files) » Views (for Drupal 7)
Version: 7.x-2.x-dev » 7.x-3.x-dev
Component: Views integration » files/upload data

Looks like that extension data comes from Views module :)

jenlampton’s picture

Status: Active » Needs review
FileSize
2.95 KB

I couldn't figure out a way to add an expression to the field in the view, so I ended up going with the "ends with" filter that string comparison uses. it works, but it's not quite what I'd intended.

jenlampton’s picture

Issue summary: View changes

add see

jenlampton’s picture

Issue summary: View changes
Status: Needs review » Closed (duplicate)

Looks like this is provided by the latest version of file entity. Closing.

imperator_99’s picture

I couldn't figure out where File Entity was providing this, so I used the patch. Unfortunately it didn't work straight out, I was getting an error regarding the SQL query in line 18 of views_handler_filter_file_extension.inc. Turns out I had to change the 'origname' column in the SELECT statement to 'filename', which is what is used in the file_managed table.

Updated patch attached, for those who need it (entirely not sure if this is the correct way to do this, since I am patching a patch).

varshith’s picture

This is indeed provided by the "file_entity" module.
After enabling the file_entity module, create a relationshiop in your view called (YOUR_FIELD:fid) and then you can use filter "File: Mime Type" (you can use contains operator there)
You can also create a view of "Files" and use them without relationships.

omnia.ibrahim’s picture

Patch for views version views-7.x-3.20

rtnilesh.gupta’s picture

double file extension it is taking any idea how to stop? like salt.php.pdf not to take in drupal 7 webform but it is taking how to alter? por stop or is there any option to rename the extension. before upload or after upload. i need custom module or is there any module?