-2

I have Drupal 7 and a file field and users can upload pdf, office documents and image. For pdf i have pdf.js formatter, office doc's have simple link to download and image show by fancybox plugin. I am need use different formatters if file have different extension. Thanks.

0

It work for me =)

$field_link_file = field_get_items('node', $node, 'field_docs_files'); $file_url = file_create_url($field_link_file[0]['uri']); $parts = pathinfo($file_url); $extension = $parts['extension']; if ($extension == 'jpg' || $extension == 'png' || $extension == 'tif') { $options = array( 'type' => 'colorbox', 'label' => 'hidden', 'settings' => array( 'colorbox_node_style' => 'large', 'colorbox_node_style_first' => '' ) ); } elseif ($extension == 'pdf') { $options = array( 'type' => 'pdf_default', 'label' => 'hidden', 'settings' => array( 'width' => '100%', 'height' => '800px' ) ); } else { $options = array( 'type' => 'text', 'label' => 'hidden', 'settings' => array( 'width' => '100%', 'height' => '800px' ) ); } $field_view_files = field_view_field('node', $node, 'field_docs_files', $options); print render($field_view_files);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.