function _file_resource_load_node_files in Services 6.3
Generates an array of base64 encoded files attached to a node.
Parameters
$nid: Number. Node ID
Return value
Array. A list of all files from the given node
File
- resources/
file_resource.inc, line 291 - File resource.
Code
function _file_resource_load_node_files($nid, $file_include_contents) {
$node = node_load($nid);
if (!isset($node->files)) {
return services_error(t('There are no files on given node.'));
}
$return = array();
foreach ($node->files as $file) {
// Do not return files that are not listed.
if (!$file->list) {
continue;
}
$return[$file->fid] = array(
'filename' => $file->filename,
'uid' => $file->uid,
'filemime' => $file->filemime,
'filesize' => $file->filesize,
'status' => $file->status,
'timestamp' => $file->timestamp,
);
// If to add content of the file.
if ($file_include_contents) {
$filepath = file_create_path($file->filepath);
$binaryfile = fopen($filepath, 'rb');
$return[$file->fid]['file'] = base64_encode(fread($binaryfile, filesize($filepath)));
fclose($binaryfile);
}
}
return $return;
}