function swftools_file_download in SWF Tools 6.3
Same name and namespace in other branches
- 5 swftools.module \swftools_file_download()
- 6 swftools.module \swftools_file_download()
- 6.2 swftools.module \swftools_file_download()
Implementation of hook_file_download().
Allows SWF Tools to work with a private file system that might include files uploaded outside the control of an upload module, e.g. FTP of large video files.
If the file is of a supported type, based on extension, then return a valid header. If any other module returns -1 for this file then access will be denied even if SWF Tools tries to allow it. See hook_file_download() for details.
File
- ./
swftools.module, line 1328 - The primary component of SWF Tools that enables comprehensive media handling.
Code
function swftools_file_download($file) {
// If SWF Tools is allowed to grant access then check to see if access will be allowed
if (variable_get('swftools_grant_access_to_private_files', SWFTOOLS_PRIVATE_ACCESS_DENIED)) {
// Get extension of file in question
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
// Get list of extensions that SWF Tools can grant access to
$extensions = variable_get('swftools_grant_access_extensions', SWFTOOLS_PRIVATE_ACCESS_ALLOWED_EXTENSIONS);
// Need access to the user object
global $user;
// Check if SWF Tools should grant access to this extension - skip the check for user #1
if ($user->uid != 1) {
$regex = '/\\.(' . ereg_replace(' +', '|', preg_quote($extensions)) . ')$/i';
if (!preg_match($regex, $file)) {
return;
}
}
// Build an array of types that SWF Tools can react to
$mime_types = _swftools_mime_types();
// If file is one of the above types, based on the extension, return headers
if (isset($mime_types[$extension])) {
return array(
'Content-Type: ' . $mime_types[$extension],
'Content-Length: ' . filesize(file_create_path($file)),
);
}
}
}