function ml_flickr_save_image in Media Library 6
Saves a Flickr picture from an URL
Parameters
url - url of image:
Return value
file object
1 call to ml_flickr_save_image()
- ml_flickr_flickr_options_form_submit in ml_image/
ml_flickr/ ml_flickr.module - Submit of image selection stage
File
- ml_image/
ml_flickr/ ml_flickr.module, line 297 - This module aims to provide some basic sources for images to use with Media Library, such as navigating on existing files and uploading new images
Code
function ml_flickr_save_image($url) {
global $user;
// URL fopen
$fd = fopen($url, 'rb');
if (!$fd) {
// TODO: issue error
return;
}
$dir = variable_get('ml_flickr_destination', ML_FLICKR_DIR);
$dest = file_create_path($dir);
if (!file_check_directory($dest, TRUE)) {
// TODO: issue error
return;
}
$filename = basename($url);
// Begin building file object.
$file = new stdClass();
$file->filename = $filename;
//$file->filepath = $_FILES['files']['tmp_name'][$source];
$file->filemime = file_get_mimetype($file->filename);
//$file->source = $source;
$file->destination = file_destination(file_create_path($dest . '/' . $file->filename), FILE_EXISTS_REPLACE);
// Copy file
$file->filepath = $file->destination;
if ($fd_dest = fopen($file->filepath, 'w+')) {
stream_copy_to_stream($fd, $fd_dest);
fclose($fd);
fclose($fd_dest);
}
// If we made it this far it's safe to record this file in the database.
$file->uid = $user->uid;
$file->status = 1;
$file->timestamp = time();
$file->filesize = filesize($file->filepath);
drupal_write_record('files', $file);
return $file;
}