Same name and namespace in other branches
  1. 4.7.x developer/examples/fileupload.module \fileupload_view()
  2. 5.x developer/examples/fileupload.module \fileupload_view()

File

developer/examples/fileupload.module, line 56
This is an example to demonstrate how to make a Drupal node support file uploads.

Code

function fileupload_view($node, $main = 0, $page = 0) {

  // Only create link to file when it is in the proper location.
  if ($node->size && file_check_location($node->filepath, variable_get('file_directory_path', 'files'))) {
    $node->body = '<a href="' . file_create_url($node->filepath) . '">' . $node->basename . '</a> (' . format_size($node->size) . ')';
  }
  elseif ($file = $node->file) {
    $node->body = $file->name . ' (' . format_size($file->size) . ')';
  }
  else {
    $node->body = basename($node->filepath) . ' (' . format_size(filesize($node->filepath)) . ')';
  }
  return theme('node', $node, $main, $page);
}