function swftools_file_download in SWF Tools 6
Same name and namespace in other branches
- 5 swftools.module \swftools_file_download()
- 6.3 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 upload outside the control of an upload module, e.g. FTP of large video files If the file is in the playlists directory then return a valid header. If the file is of a supported type, based on extension, then return a valid header. Note: 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 1224
Code
function swftools_file_download($file) {
// See if we have a playlist - SWF Tools can allow access to those since it creates them
$playlist_path = preg_quote(variable_get('swftools_playlist_path', SWFTOOLS_PLAYLIST_PATH));
if (preg_match('/^' . $playlist_path . '/', $file)) {
return array(
'Content-Type: ' . $mime_types[$extension],
'Content-Length: ' . filesize(file_create_path($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_GRANT_ACCESS_TO_PRIVATE_FILES)) {
// Get extension of file in question
$extension = pathinfo($file, PATHINFO_EXTENSION);
// Get list of extensions that SWF Tools can grant access to
$extensions = variable_get('swftools_grant_access_extensions', SWFTOOLS_GRANT_ACCESS_EXTENSIONS);
// Need access to the user object
global $user;
// Check if SWF Tools should grant access - 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 = array(
'swf' => 'application/x-shockwave-flash',
'flv' => 'application/octet-stream',
'xml' => 'text/xml',
'mp3' => 'audio/mpeg',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/gif',
);
// If file is one of the above types, based on the extension, return headers
if ($mime_types[$extension]) {
return array(
'Content-Type: ' . $mime_types[$extension],
'Content-Length: ' . filesize(file_create_path($file)),
);
}
}
}