By saitanay on
Trying to create a node progrmatically after attaching a file, already existing on the server
but the attached file is always blank and of size ZERO.. any hints?
<?php
if ($bill['FILENAME']) {
$filename = substr($bill['FILENAME'], 16);
dsm("/var/www/vhosts/xxx.org/public_html/migration/d1/sites/default/files/temp/Upload/" . $filename);
$file_temp = file_get_contents("/var/www/vhosts/xxx.org/public_html/migration/d1/sites/default/files/temp/Upload/" . $filename);
$file_temp = file_save_data($file_temp, "public://publicpolicy/" . $filename, FILE_EXISTS_RENAME);
$file_temp = (array) $file_temp;
$file_temp['display'] = 1;
$node->field_tm_bft_file = array('und' => array(
'0' => $file_temp
)
);
}
node_object_prepare($node);
node_submit($node);
node_save($node);
?>