http://drupal.org/node/348204
I found this thread extremely helpful, and I'm almost to where I need to be, but I'm not sure how to work through the further complications that a multi-value file field causes with arrays. Like the poster in that thread, I know just enough to be dangerous, so I'm sure I'm missing something obvious.
I have an imagefield where the user can upload multiple images, and I am trying to get to the filepaths for each of the images. I've tried variations on the code below, and I just seem to be trying to pull elements out of the array(s) in the wrong places. Any help would be greatly appreciated.
I've been trying variations on this theme:
<?php
$galleryImages = $data->node_data_field_kitchen_gallery_field_kitchen_gallery_fid;
foreach ($galleryImages as $galleryImage) {
$galleryImage = field_file_load($galleryImage);
echo $galleryImage['filepath'] . '<br />';
}
?>
Comments
Comment #1
oxyc CreditAttribution: oxyc commentedThanks for assisting me,
your post and the link helped me out as well and I figured out how to solve the problem (yes it's a tiny error).
Replace line 5 with:
$galleryImage = field_file_load($galleryImage['fid']);
Hope that works
Comment #2
grasmash CreditAttribution: grasmash commentedNice script. I ran into the need for a very similar script. Here's the issue I was having:
When uploading multiple files with filefield, Views would only honor the "hide if empty" setting if there were absolutely no files attached. When, for instance, four (of the possible eight) files were attached it would display the four empty rows with their labels. I had to add a php script using views customfield that would cycle through all of the attachments and print a custom output for each not-null row. This script mimics the normal generic file output setting for a filefield row (icon, title linked to file, filesize):
Hope that helps someone. There was very little info online about hiding select rows of a filefield multiple attachment field in views.
Comment #3
KerriO CreditAttribution: KerriO commentedThanks, you two, for your comments. The structure ended up changing for this so I didn't need to do it through views in the end, but these comments are very helpful, as I'm sure something similar will pop up in the future! I see now that the "fid" was definitely what I was missing!
Comment #4
KerriO CreditAttribution: KerriO commentedComment #5
ginga8 CreditAttribution: ginga8 commentedI am wondering if someone here maybe able to help me, I too am trying to do the same thing as above but with files and it looks like exactly what I am looking for. Here is what I have so far:
warning: Invalid argument supplied for foreach() in /home/swdev2/public_html/sites/all/modules/views_customfield/includes/views_customfield_handler_field_phpcode.inc(118) : eval()'d code on line 4.
In the SQL returned by the view, I see no mention of the field_file, am I to structure my view a certain way. Not every Tender Content type will have files and if they do they can have one to many.
Any help would be greatly appreciated.
Thanks
Comment #6
ginga8 CreditAttribution: ginga8 commentedMeant to change status to active
Comment #7
guysaban CreditAttribution: guysaban commentedHi GingaB,
Not sure I exactly understand what you need. I may be wrong but I understand the fid is a unique File ID - so one fid per file.
In your code you have a foreach loop. I would leave that up to the Views query which will output multiple rows (each row with the fields you specified for the query (i.e. in the Views interface) - in this case the fid field.)
Based on this I would change your views_customfield as follows:
Comment #8
leovw CreditAttribution: leovw commentedThanks for this - It was just what I was looking for (#2)
Comment #9
grasmash CreditAttribution: grasmash commentedGlad I could help! I still use that snippet on many sites : )
Comment #10
Abeaudrian CreditAttribution: Abeaudrian commentedHi
How are you? Will this script allow me to still get Lightbox2 functionality for my images?