$file->fid))->fetch(PDO::FETCH_ASSOC); foreach ((array)$values as $key => $value) { $file->{$key} = $value; } } /** * Respond to a file is being saved. * * @param $file * The file object being saved. * @return * None. * @see file_save() */ function hook_file_save(&$file) { } /** * Report problems with a file. * * @param $file * The file object being validated. * @return * An optional array of error messages. If no problems were detected return * NULL. * @see file_save() */ function hook_file_validate($file) { } /** * Respond to a file being added. * * @param $file * The file that has just been created. * @return * None. * @see file_save() */ function hook_file_insert(&$file) { } /** * Respond to a file being updated. * * @param $file * The file that has just been updated. * @return * None. * @see file_save() */ function hook_file_update(&$file) { } /** * Respond to a file that has been copied. * * @param $file * The newly copied file object. * @param $source * The original file before the copy. * @return * None. * @see file_copy() */ function hook_file_copy($file, $source) { { } /** * Respond to a file that has been moved. * * @param $file * The updated file object after the move. * @param $source * The original file object before the move. * @return * None. * @see file_move() */ function hook_file_move($file, $source) { } /** * Report the number of times a file is referenced by a module. * * This hook is called to determine if a files is in use. Multiple modules may * be referencing the same file and to prevent one from deleting a file used by * another this hook is called. * * @param $file * The file object being checked for references. * @return * If the module uses this file return an array with the module name as the * key and the value the number of times the file is used. * @see file_delete() * @see upload_file_references() */ function hook_file_references($file) { // If upload.module is still using a file, do not let other modules delete it. $count = db_query('SELECT COUNT(*) FROM {upload} WHERE fid = :fid', array(':fid' => $file->fid))->fetchField(); if ($count) { // Return the name of the module and how many references it has to the file. return array('upload' => $count); } } /** * Respond to a file being deleted. * * @param $file * The file that has just been deleted. * @return * None. * @see file_delete() * @see upload_file_delete() */ function hook_file_delete($file) { // Delete all information associated with the file. db_delete('upload')->condition('fid', $file->fid)->execute(); } /** * Respond to a file that's status has changed. * * @param $file * The file being changed. * @return * None. * @see hook_file_status() */ function hook_file_status($file) { } /** * Control access to private file downloads and specify HTTP headers. * * This hook allows modules enforce permisisons on file downloads when the * private file download method is selected. Modules can also provide headers * to specify information like the file's name or MIME type. * * @param $filepath * String of the file's path. * @return * If the user does not have permission to access the file, return -1. If the * user has permission, return an array with the appropriate headers. If the * file is not controlled by the current module, the return value should be * NULL. * @see file_download() */ function hook_file_download($filepath) { // Check if the file is controlled by the current module. $filepath = file_create_path($filepath); $result = db_query("SELECT f.* FROM {files} f INNER JOIN {upload} u ON f.fid = u.fid WHERE filepath = '%s'", $filepath); if ($file = db_fetch_object($result)) { if (!user_access('view uploaded files')) { return -1; } return array( 'Content-Type: ' . $file->filemime, 'Content-Length: ' . $file->filesize, ); } }