Filefield or imagefield
Flying Drupalist - October 21, 2009 - 11:09
| Project: | FileField |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
On a certain node type, I would like my users to be able to upload anything, be it an image or a file. Can I use filefield and have the module recognize that the uploaded file is an image and then magically transform into imagefield (software like vbulletin already do this)? This is way better than having 2 fields just sitting there.
Thanks.

#1
You can't magically make a FileField and ImageField, CCK will always recognize a widget type as whatever it was original created as. However you can accomplish what you're asking simply by theming the FileField Widget to show an image if an image is uploaded. You could do similar things to make audio files have a player or video files show a thumbnail.
To do this, just override the theme_filefield_widget_preview() function, which provides the preview next to the uploaded file. Take the function out of filefield_widget.inc, copy it into your theme's template.php, and rename it to [yourtheme]_filefield_widget_preview(). Then do any changes you want, and clear your Drupal caches at admin/settings/performance.
#2
I'm thinking, enable both widgets, but when uploading let js check for file extension, and if is jpg/gif/png use imagefield otherwise use filefield?
Otherwise you would lose the features of imagefield, which are too numerous to list.
#3
There is no easy way to accomplish this. It sounds like a difficult thing to implement that would be very sensitive to changes on the site (such as theming the node form, or positions of the FileField and ImageField). ImageField is purely built on top of FileField, so between the two of them they should have very similar functionality.
#4
I would love to see this too.
I've long thought about having FileField detect the image types and display them with the ImageField widget.