I'm trying to use this URL http://img.youtube.com/vi/'.$id.'/0.jpg to load image.
now, need load the content inside on Image object for using the function return $this->Image()->CMSThumbnail() and display the image on gridfield.
any idea?
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
I'm trying to use this URL http://img.youtube.com/vi/'.$id.'/0.jpg to load image.
now, need load the content inside on Image object for using the function return $this->Image()->CMSThumbnail() and display the image on gridfield.
any idea?
private function getFileByURL($url, $fileName){
$basePath = Director::baseFolder() . DIRECTORY_SEPARATOR;
$folder = Folder::find_or_make(self::$media_upload_folder); // relative to assets
$relativeFilePath = $folder->Filename . $fileName;
$fullFilePath = $basePath . $relativeFilePath;
if (!file_exists($fullFilePath)){
// download the file
$fp = fopen($fullFilePath, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
}
$file = new Image();
$file->ParentID = $folder->ID;
$file->OwnerID = (Member::currentUser()) ? Member::currentUser()->ID : 0;
$file->Name = basename($relativeFilePath);
$file->Filename = $relativeFilePath;
$file->Title = str_replace('-', ' ', substr($fileName, 0, (strlen ($fileName)) - (strlen (strrchr($fileName,'.')))));
$file->write();
return $file;
}
using example
public function loadYoutubeThumbFromID($id){
$f = $this->getFileByURL('http://img.youtube.com/vi/'.$id.'/1.jpg', $id . '-thumb.jpg');
return $f->CMSThumbnail();
}