file id

Attach an existing file to a node programmatically



/**
 * Code that will enable attachment of a pre-existing file on the filesystem
 * to a node that requires it. 
 */
function attach_file(&$node, $file_location, $lang = 'en') {
  global $doc_base_path;

  $file_location = str_replace('\\','/', $file_location);

  $actual_file = $doc_base_path . "/" . stripslashes($file_location);
  if (!file_exists($actual_file)) {
    print "**** FILE NOT FOUND ****\n";
    print $actual_file;
    print "^^^^ FILE NOT FOUND ^^^^\n";
  } else {

    print "File GOOD\n";
    print "Filesize: " . filesize($actual_file);
  }
Subscribe to RSS - file id