function _auditfiles_not_in_database_get_file_data in Audit Files 7.4
Retrieves file data from the database and checks if it is on the server.
Parameters
string $filepathname: The path and name of the file to prepare for display.
string $date_format: The format to display time/date values in.
Return value
array The row for the table on the report, with the file's information formatted for display.
2 calls to _auditfiles_not_in_database_get_file_data()
- auditfiles_not_in_database_form in ./
auditfiles.notindatabase.inc - Generates the report.
- _auditfiles_not_in_database_batch_display_process_batch in ./
auditfiles.notindatabase.inc - The batch process for displaying the files.
File
- ./
auditfiles.notindatabase.inc, line 688 - Generates a report showing files on the server, but not in the database.
Code
function _auditfiles_not_in_database_get_file_data($filepathname, $date_format) {
// Convert the path name to a Drupal URI scheme for comparison in the
// database.
// Get the path of the currently used file scheme.
$files_path = variable_get('file_' . file_default_scheme() . '_path', conf_path() . '/files');
// Remove the path to the files directory.
if ($files_path != '') {
$matches = array();
preg_match_all('~(.*)(' . $files_path . ')(.*)~', $filepathname, $matches);
$match = end($matches);
$match = reset($match);
$file_uri = file_build_uri($match);
}
// See if the file is in the database.
$query = "SELECT fid FROM {file_managed} WHERE uri = :file_uri";
$stored_file = db_query($query, array(
':file_uri' => $file_uri,
))
->fetchField();
if (empty($stored_file)) {
// This file is not in the database.
// Get the filename from the filepathname.
$filename = substr($filepathname, strrpos($filepathname, '/') + 1);
// Return the file.
return array(
'filepathname' => $filepathname,
'filemime' => file_get_mimetype($filepathname),
'filesize' => number_format(filesize($filepathname)),
'filemodtime' => format_date(filemtime($filepathname), $date_format),
'filename' => $filename,
);
}
}