node_save

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);
  }

Attach an Existing File to a Node... Programmatically

and the need to consider languages / translations.

Hi!! I'm excited 'cause I just spent another hour figuring out something that wasn't exactly rocket science... but a fairly obscure solution for my "special case".

Use node_load and node_save to Import Data

So you have a CSV file that as a developer, you already know how to manipulate and read from. You also know how to create objects or arrays from this CSV file. But you're running Drupal 6 and you want the content in this file to be content on the site. Most dev guys will tell you that you need to write custom queries to extend the Drupal Schema and then write custom code to get it on the page.

Don't forget... BYODD: Backup Your Own Database Dummy! We're Not responsible for you screwing up your database if you follow these directions.

Subscribe to RSS - node_save