Example #1
0
 /** Fetch file from remote URL
  * @param string $url URL of file
  * @param string $dir Directory to save file
  * @return self
  * @throws System\Error\File
  * @throws System\Error\Connection
  */
 static function fetch($url)
 {
     $u = explode('/', $url);
     $name = end($u);
     $data = \Helper\Offcom\Request::get($url);
     if ($data->ok()) {
         $f = new self(array("name" => $name));
         $f->set_content($data->content);
         $f->size = $data->size;
         $f->mime = $data->mime;
         return $f;
     } else {
         throw new \System\Error\Connection('Couldn\'t fetch file', sprintf('HTTP error %s ', $data->status));
     }
 }