Hi all,

I am using CCK Image module and want to show those images using a customized view (Views module)
When I use (print_r) to get available arrays I get the following value for image field:

[node_data_field_small_image_field_small_image_title] => globe_66.jpg

Well everything is fine up to this level, but this actually doesn't show me the actual path of the image, and it is only the filename! how can I get the full path string?

Many thanks in advance
Luca

Comments

jastraat’s picture

I assume you're using imagefield for CCK -
I'm guessing your field name is field_small_image - but you should double-check that.

You can try the following to return the path of the first image in the array (If it's a multi-value field there may be more):

$image_array = $node->field_small_image;
$path = base_path() . $image_array[0]['filepath'];

Let me know if that worked for you!

------------------------------
http://fraggles.artsci.wustl.edu (Drupal user documentation and development blog)

WoozyDuck’s picture

Thank you for your reply but I actually don't get that array
All I get from that field is the following items:

[node_data_field_small_image_field_small_image_fid] => 637
[node_data_field_small_image_field_small_image_title] => globe_66.jpg
[node_data_field_small_image_field_small_image_alt] => Globe

Would it be possible to get the full path of the image using (node_data_field_small_image_field_small_image_fid) somehow?

Many thanks

WoozyDuck’s picture

I am not sure if Drupal had any core function to get the filepath using FID (FileID) but I just got it using the following query:

$result = db_query("SELECT filepath FROM {files} WHERE fid = '%s'", $fid);

The result would give me the full file path of the image :)

jastraat’s picture

I use the array function I provided to get the filepath in template.php. I set it as a variable so I can use it as background images outside of the node area. Strange that the filepath variable was excluded from the array in the view!

------------------------------
http://fraggles.artsci.wustl.edu (Drupal user documentation and development blog)

kuzyakiev’s picture

Thank you very very much!

WoozyDuck’s picture

I am not sure if Drupal had any core function to get the filepath using FID (FileID) but I just got it using the following query:

$result = db_query("SELECT filepath FROM {files} WHERE fid = '%s'", $fid);

The result would give me the full file path of the image :)

WoozyDuck’s picture

I am not sure if Drupal had any core function to get the filepath using FID (FileID) but I just got it using the following query:

$result = db_query("SELECT filepath FROM {files} WHERE fid = '%s'", $fid);

The result would give me the full file path of the image :)

fp’s picture

$fid is a integer.

$result = db_query("SELECT filepath FROM {files} WHERE fid = %d", $fid);

would be more appropriate.

WoozyDuck’s picture

Thank you very much :)

raff77’s picture

So there's no other way to get an image path ina view. Mental.

Sometimes I'm not sure about this Drupal malarky.

I found this, which was quite helpful http://2bits.com/articles/drupal-using-imagecache-with-views-and-cck-ima...

engr.fahad’s picture

Greetings!
I am using cck image file field module and it's dependensies. I have a form developed with cck field types. When I upload am image with the image fieldtype it only shows me a small image on the form. What I want is that when the user clicks on the small image he should view a full size verison of that image that is its actual size. I also use image link module but cant get the functionality.
If node is an option then how can the form make a node automatically when it uploads a file while filling the form.
Please tell me some steps since I am a complete beginner and have no idea of php.

Many Thanks

Best Regards

panhead490’s picture

Well thanks to that link, I learned you can use field_file_load ... no need for db queries or anything. There's a bit more info on the 2bits.com site if you are interested.

I used it like this to call a view from php:

$view = views_get_view('events');  // Use your own view name here
$view->is_cacheable = FALSE;
$view->set_display('default');
$view->display_handler->set_option('items_per_page', 0);
$view->preview();

foreach ($view->result as $result) {
	// print_r($result); <-- Use this to figure out the crazy long fid value here, it's different for every content type
	$eventImageArray = field_file_load($result->INSERT_YOUR_FID_HERE);
	$eventImagePath = $eventImageArray['filepath'];
}