public function MediaUnsplashHandler::preSave in Media Unsplash 7
Prepare file object.
Parameters
object $file_obj: File object upon manipulation is done.
Throws
\Exception
File
- includes/
MediaUnsplashHandler.inc, line 28 - Definition of MediaUnsplashHandler.
Class
- MediaUnsplashHandler
- A class for managing the addition of Internet files.
Code
public function preSave(&$file_obj) {
// Copy the remote file locally.
$remote_uri = $file_obj->uri;
// Check mimetype - Unsplash images are without extension.
$image_data = $this
->imageInfo($file_obj->uri);
$file_obj->filemime = $image_data->filemime;
$file_obj->filename = $image_data->filename;
$local_uri = file_stream_wrapper_uri_normalize('temporary://' . $image_data->filename);
if (!@copy($remote_uri, $local_uri)) {
throw new Exception('Unable to add file ' . $remote_uri);
}
$file_obj = file_uri_to_object($local_uri);
}