function brightcove_remote_image in Brightcove Video Connect 7.5
Same name and namespace in other branches
- 6.2 brightcove.module \brightcove_remote_image()
- 6 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.6 brightcove.module \brightcove_remote_image()
Function that saves a remote image as a local file.
Parameters
string $url: Remote image URL.
Return value
string|bool Returns FALSE if image doesn't exist, cannot be saved or is not image (based on extension). Returns $file object if image already exists or was saved correctly.
1 call to brightcove_remote_image()
- theme_brightcove_field_image in brightcove_field/
brightcove_field.formatters.inc - Theme function to render brightcove images.
File
- ./
brightcove.module, line 442 - 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 = drupal_realpath(file_default_scheme() . '://brightcove_thumbnail');
$final_file = $fullpath . '/' . $path['basename'];
if (file_exists($final_file)) {
return file_build_uri('brightcove_thumbnail/' . $path['basename']);
}
// Perform basic extension check.
if (!in_array(drupal_strtolower($path['extension']), array(
'jpg',
'jpeg',
'png',
'gif',
))) {
return FALSE;
}
if (!file_prepare_directory($fullpath, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
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 file_build_uri('brightcove_thumbnail/' . $path['basename']);
}