下面是网上找来的代码。。
加入templates.php后网站就变空白了。。
function coverupload_form_submit($form, &$form_state) {
if(isset($form_state['values']['cover']) && $form_state['values']['cover'] != '') {
$file = file_load($form_state['values']['cover']);
// Change status to permanent.
$file->status = FILE_STATUS_PERMANENT;
// Save.
file_save($file);
$node = node_load($form_state['storage']['rid']);
$node->field_release_cover['und'][0] = (array)$file;
if($node = node_submit($node)) { // Prepare node for saving
node_save($node);
}
// Delete the old file
file_delete($file);
$new_file = $node->field_release_cover['und'][0]['fid']));
$pattern = '/^(.+)(\.jpg)$/';
preg_match($pattern, $new_file->uri, $matches);
$new_uri = $matches[1].'_'.substr(md5(rand(0,10000)), 0, 3).$matches[2];
file_move($file, $new_uri);
}
}