示例#1
0
 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);
 }
示例#2
0
 /**
  * Determines whether or not the resource 'needs' a preview image.
  * Large files and PDFs are two examples.
  *
  * @param string $sha
  * @return bool        True if the resource needs a preview.
  */
 protected function _needsPreview($sha)
 {
     $path = $this->path($sha, $sha);
     # Anything greater than a megabyte.
     if (filesize($path) > 1000000) {
         return true;
     }
     $mime = \Relic\Mime::mime($path);
     # PDFs and TIFFs need previews, too.
     if (in_array($mime, array('application/pdf', 'image/tiff'))) {
         return true;
     }
     return false;
 }