tags:

views:

716

answers:

1

Hey Everyone,

Just wondering can anyone tell me how to access the file field variable in drupal? I can access the rest of the node's variabels with the following php:

$node->field_event[0]['value'];

But I do not know how to access the content of a file field called field_pdf.

I know it is created with something like:

$node->field_pdf = array( array( 'fid' => $file->fid, 'title' => basename($file->filename), 'filename' => $file->filename, 'filepath' => $file->filepath, 'filesize' => $file->filesize, 'mimetype' => $mime, 'description' => basename($file->filename), 'list' => 1, ), );

I solved thie problem with the following snippet:

$node->field_pdf[0]['filepath'];

Hope this helps somebody.

j

+1  A: 

I am not 100% sure I got what your doubt is, however on a node with a file_field (a series of PDF attachments in my case) the $node object has a property called files which structure is like this:

[files] => Array
    (
        [190] => stdClass Object
            (
                [fid] => 190
                [uid] => 1
                [filename] => attachmentname.pdf
                [filepath] => sites/default/files/attachmentname_0.pdf
                [filemime] => application/pdf
                [filesize] => 295159
                [status] => 1
                [timestamp] => 1255855095
                [nid] => 36644
                [vid] => 36603
                [description] => attachmentdescription
                [list] => 1
                [weight] => 0
            )

I also suggest you install drupalforfirebug this is an awesome module that - in combination with firebug - allows you to see the structure of all your nodes / forms / user objects, etc... very handy!

HTH.

PS: If this is not what you are looking for, please specify in a comment how can I help better.

mac
Thanks for the drupalforfirebug tip. I'm a newbie with drupal so still learning the ropes. I have one file tupe with the node specified by the field_pdf. From your suggestion, I think I can access the file path with this:$node->files[0]['filepath'];Is this correct?Thanks for your help, much appreciated. j
slotishtype
Cheers dude, got it working.j
slotishtype
Welcome to the Drupal community, then! A few days back somebody posted a couple of questions about learning Drupal, in case you are interested: http://stackoverflow.com/questions/1791553/the-most-common-pitfalls-for-a-beginner-drupal-user and http://stackoverflow.com/questions/1791035/good-beginners-material-advice-on-drupal, but if you search here on SO you will find also other older post with a similar focus.
mac
Cheers, I bought a couple of those books already. Just trying to get as familar as possible at the moment. thanks again,j
slotishtype