You are here

function file_service_get in Services 6.2

Same name and namespace in other branches
  1. 6 services/file_service/file_service.inc \file_service_get()
  2. 7 services/file_service/file_service.inc \file_service_get()

Get all elements from a given file

Parameters

$fid: Number. File ID

Return value

Array. All elements for a given file

1 string reference to 'file_service_get'
file_service_service in services/file_service/file_service.module
Implementation of hook_service().

File

services/file_service/file_service.inc, line 16
Link general file functionalities to services module.

Code

function file_service_get($fid) {
  if ($file = db_fetch_array(db_query('SELECT * FROM {files} WHERE fid = %d', $fid))) {
    $filepath = file_create_path($file['filepath']);
    $binaryfile = fopen($filepath, 'rb');
    $file['file'] = base64_encode(fread($binaryfile, filesize($filepath)));
    fclose($binaryfile);
    return $file;
  }
  else {
    return services_error(t('There is no file with the given ID.'));
  }
}