views:

210

answers:

3

What function in Drupal gets file attachment path?

Edit: the attachments provided by Upload module in system section. But since you mentioned there may be another way around it. Maybe I could achieve may goals using FileField module so if you could tell me how to get a direct link of a file uploaded by FileField module that may also be very helpful.

Edit 2: Ok I will start from my main and final objective:

It is to get an image linking to a file which visibility I could be managed using CCK module.

I am doing this step by step. So now I have written a code which generates the needed image and I have added that image to one of content types teaser. I found a way to warp my image in a tag and I had dug up simple attachments url. So my next step is to advance from simple upload attachment to the one added by FileFields and from odd looking HTML pace in all PHP document into beautifully managed CCK field.

  • How to fetch file path of a file uploaded FileFields?
  • Some plain and at the same time rich tutorials for making custom fields for CCK module.
A: 

Don't direct links of file attachments appear below the uploaded file for the core Upload module?

Kevin
+1  A: 

Assuming you know how to get the $node object for a node containing a file attachment, this is super easy:


Upload (core)

$file = upload_load($node);
echo $file[1]->filepath;

Where 1 is the index of the file. Upload can let you upload more than one file, so file 2 would have an index of 2 and so on. If there's only one file, it'll always be 1.


FileField

echo $node->field_fieldname[0]['filepath'];

Where field_filename is the short name you've used for the field, and 0 is the index of the field. CCK fields let you have multiple values in one field, so 0 would be the first, 1 would be the second, etc. If you only have one value, it'll always be 0.

Note: if you want to get the rendered output of the FileField using its formatters, you can just use $field_fieldname in your node template, or if you want to store the rendered output, you can use:

echo content_format('field_fieldname', $node->field_fieldname[0]);

Upload is a sad little module, and has been completely replaced with a core implementation of FileField in Drupal 7. If you have the option to use FileField, you should.

Mark Trapp
Thanks this should do it ;D
Povylas
A: 

Since you are trying to use images, you should use http://drupal.org/project/imagefield CCK module in order to add images to specified content type. After that using the Display fields tab in Content type configuration you can specify how image would be presented (as a link, image, image with link to node...) both in teaser and body view.

bas