function asset_file_update in Asset 5.2
Same name and namespace in other branches
- 6 asset.types.inc \asset_file_update()
Implementation of hook_asset_type('update') for file asset type
Related topics
File
- ./
asset.types.inc, line 181 - This file is included by asset_asset_type() and includes all the file and directory specific functions
Code
function asset_file_update(&$asset) {
$file = file_check_upload('upload');
$asset_path = variable_get('asset_file_directory_path', '');
$dest = $asset_path ? $asset_path . '/' . $file->filename : $file->filename;
if ($file = file_save_upload($file, $dest)) {
$file->fid = db_next_id('{files}_fid');
// delete the old file and remove db entry
file_delete($asset->file['filepath']);
db_query("DELETE FROM {files} WHERE fid=%d", $asset->file['fid']);
// add the new file and update the relationship
db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $file->fid, 0, $file->filename, $file->filepath, $file->filemime, $file->filesize);
db_query("UPDATE {asset_files} SET fid=%d WHERE aid=%d", $file->fid, $asset->aid);
}
}