Skip to content

Instantly share code, notes, and snippets.

Created November 14, 2014 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6a7043126f9bd4748462 to your computer and use it in GitHub Desktop.
Save anonymous/6a7043126f9bd4748462 to your computer and use it in GitHub Desktop.
<?php
//...
if ($this->Video()->exists()) {
$basePath = Director::baseFolder() . DIRECTORY_SEPARATOR;
$folder = Folder::find_or_make('video'); // relative to assets
$relativeFilePath = $folder->Filename . 'video-' . $this->Video()->ID . '-thumb.jpg';
$fullFilePath = $basePath . $relativeFilePath;
if (!file_exists($fullFilePath)) {
$fp = fopen($fullFilePath, 'w');
$ch = curl_init($this->Video()->ThumbnailURL);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
$image->setFilename($relativeFilePath);
return $image;
}
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment