function brightcove_remote_image in Brightcove Video Connect 6
Same name and namespace in other branches
- 6.2 brightcove.module \brightcove_remote_image()
- 7.7 brightcove.module \brightcove_remote_image()
- 7.2 brightcove.module \brightcove_remote_image()
- 7.3 brightcove.module \brightcove_remote_image()
- 7.4 brightcove.module \brightcove_remote_image()
- 7.5 brightcove.module \brightcove_remote_image()
- 7.6 brightcove.module \brightcove_remote_image()
Function that saves a remote image as a local file.
Parameters
$url: Remote image URL.
Return value
Returns FALSE if image doesn't exist, cannot be saved or is not image (based on extension). Returns local file path if image already exists or was saved correctly.
4 calls to brightcove_remote_image()
- brightcove_cck_browse in brightcove_cck/
brightcove_cck.browse.inc - This function is a callback for modalframe window, providing an access to browse videos.
- theme_brightcove_cck_lightbox2_imagecache in brightcove_cck/
brightcove_cck.formatters.inc - Theme callback for Lightbox2 with imagecache player.
- theme_brightcove_cck_node_image_imagecache in brightcove_cck/
brightcove_cck.formatters.inc - Theme callback for imagecache image
- theme_brightcove_cck_node_link_imagecache in brightcove_cck/
brightcove_cck.formatters.inc - Theme callback for imagecache image linking to node
File
- ./
brightcove.module, line 177 - Brightcove module is an integration layer between any modules using Brightcove API. It makes all necessary checks for the API and makes settings available to the user.
Code
function brightcove_remote_image($url) {
$parse = parse_url($url);
$path = pathinfo($parse['path']);
$fullpath = file_directory_path() . '/brightcove_thumbnail';
$final_file = $fullpath . '/' . $path['basename'];
if (file_exists($final_file)) {
return $final_file;
}
// Perform basic extension check.
if (!in_array(strtolower($path['extension']), array(
'jpg',
'jpeg',
'png',
'gif',
))) {
return FALSE;
}
if (!file_check_directory($fullpath, FILE_CREATE_DIRECTORY)) {
return FALSE;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Causes a warning if PHP safe mode is on.
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$rawdata = curl_exec($ch);
if ($fp = @fopen($final_file, 'x')) {
fwrite($fp, $rawdata);
fclose($fp);
}
return $final_file;
}