Same name and namespace in other branches
- 4.6.x developer/examples/fileupload.module \fileupload_update()
- 4.7.x developer/examples/fileupload.module \fileupload_update()
Implementation of hook_update().
The node is being updated, save changes to the file infomation to the database.
File
- developer/
examples/ fileupload.module, line 213 - This is an example to demonstrate how to make a Drupal node support file uploads.
Code
function fileupload_update($node) {
$newfile = $node->file->filepath;
$oldfile = db_result(db_query('SELECT filepath FROM {fileupload} WHERE nid = %d', $node->nid));
// only make changes if there was a new file.
if ($newfile) {
if ($newfile != $oldfile) {
// delete the old file
file_delete($oldfile);
}
// update the database
$file = $node->file;
db_query("UPDATE {fileupload} SET filename = '%s', filepath = '%s', filemime = '%s', filesize = %d WHERE nid = %d", $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->nid);
}
}