public function execute($data) { $this->_loadModels(); $tmp = tempnam(sys_get_temp_dir(), 'ARCS'); $url = $data['url']; if (!preg_match('/^(http|https|ftp)/', $url)) { throw new Exception('Not a valid URL'); } if (!copy($data['url'], $tmp)) { throw new Exception('Could not read URL'); } $this->Resource->fromFile(array('tmp_name' => $tmp, 'name' => basename($url), 'size' => filesize($tmp), 'type' => \Relic\Mime::mime($tmp)), $data); }
/** * Puts a default thumbnail within the path, given a MIME type. * * We don't create thumbnails during the Request-Response loop, but * we'll copy over a placeholder. * * @param string $sha * @return void */ protected function _setDefaultThumb($sha) { $types = \Relic\Mime::extensions($this->path($sha, $sha)); $image = 'generic'; foreach ($types as $type) { if (is_file(IMAGES . 'default_thumbs' . DS . $type . '.png')) { $image = $type; break; } } copy(IMAGES . 'default_thumbs' . DS . $image . '.png', $this->path($sha, 'thumb.png')); }