Access imagefield file object during node create/update I have a content type with an imagefield. I need to get a reference to the file object during node save or update, so I can do something with it.

function foo_node_presave($node){
    if ($node-&gt;type ==='foo'){
        $filename = $node-&gt;original-&gt;field_foo_image['und'][0]['filename'];
    }


In the above code, $filename isn't populated yet when a new node is being created. It does work during a node update if there was already a file in that field.

How can I get a reference to the file object in a filefield/imagefield in a hook during node creation?
Even if the field hasn't been updated yet you should have access to the fid column (the file ID), which you can use in conjunction with the file_load() function to get the filename:

// Load a file object based on the fid column fo the field.
$file = file_load($node-&gt;field_foo_image[$node-&gt;language][0]['fid'];

// Get the filename.
$filename = $file-&gt;filename;