public function get_file($url, $file = '') { global $CFG; //$CFG->repository_no_delete = true; $path = $this->prepare_file($file); $fp = fopen($path, 'w'); $c = new curl(); $c->download(array(array('url' => $url, 'file' => $fp))); return $path; }
/** * Download a file, this function can be overridden by * subclass. * * @global object $CFG * @param string $url the url of file * @param string $filename save location * @return string the location of the file * @see curl package */ public function get_file($url, $filename = '') { global $CFG; $path = $this->prepare_file($filename); $fp = fopen($path, 'w'); $c = new curl; $c->download(array(array('url'=>$url, 'file'=>$fp))); return array('path'=>$path, 'url'=>$url); }
/** * Download a file from alfresco * * @param string $uuid a unique id of directory in alfresco * @param string $path path to a directory * @return array */ public function get_file($uuid, $file = '') { $node = $this->user_session->getNode($this->store, $uuid); $url = $this->get_url($node); $path = $this->prepare_file($file); $fp = fopen($path, 'w'); $c = new curl; $c->download(array(array('url'=>$url, 'file'=>$fp))); fclose($fp); return array('path'=>$path, 'url'=>$url); }
/** * Static method to create cache from url * * @param mixed $ref file reference * @param string $url file url * @param array $options options * @return string cached file path */ public static function create_from_url($ref, $url, $options = array()) { $instance = self::get_instance($options); $cachedfilepath = $instance->generate_filepath($ref); $fp = fopen($cachedfilepath, 'w'); $curl = new curl(); $curl->download(array(array('url' => $url, 'file' => $fp))); // Must close file handler. fclose($fp); return $cachedfilepath; }
/** * * @param string $photo_id * @param string $file * @return string */ public function get_file($photo_id, $file = '') { global $CFG; $result = $this->flickr->photos_getSizes($photo_id); $url = ''; if(!empty($result[4])) { $url = $result[4]['source']; } elseif(!empty($result[3])) { $url = $result[3]['source']; } elseif(!empty($result[2])) { $url = $result[2]['source']; } $path = $this->prepare_file($file); $fp = fopen($path, 'w'); $c = new curl; $c->download(array( array('url'=>$url, 'file'=>$fp) )); return array('path'=>$path, 'url'=>$url); }
/** * * @global object $CFG * @param string $photo_id * @param string $file * @return string */ public function get_file($photo_id, $file = '') { global $CFG; $info = $this->flickr->photos_getInfo($photo_id); if ($info['owner']['realname']) { $author = $info['owner']['realname']; } else { $author = $info['owner']['username']; } $copyright = get_string('author', 'repository') . ': ' . $author; $result = $this->flickr->photos_getSizes($photo_id); // download link $source = ''; // flickr photo page $url = ''; if (!empty($result[4])) { $source = $result[4]['source']; $url = $result[4]['url']; } elseif (!empty($result[3])) { $source = $result[3]['source']; $url = $result[3]['url']; } elseif (!empty($result[2])) { $source = $result[2]['source']; $url = $result[2]['url']; } $path = $this->prepare_file($file); $fp = fopen($path, 'w'); $c = new curl(); $c->download(array(array('url' => $source, 'file' => $fp))); // must close file handler, otherwise gd lib will fail to process it fclose($fp); if (!empty($this->usewatermarks)) { $img = new moodle_image($path); $img->watermark($copyright, array(10, 10), array('ttf' => true, 'fontsize' => 12))->saveas($path); } return array('path' => $path, 'url' => $url, 'author' => $info['owner']['realname'], 'license' => $this->license4moodle($info['license'])); }
/** * Download a file, this function can be overridden by subclass. {@link curl} * * @param string $url the url of file * @param string $filename save location * @return array with elements: * path: internal location of the file * url: URL to the source (from parameters) */ public function get_file($url, $filename = '') { global $CFG; $path = $this->prepare_file($filename); $fp = fopen($path, 'w'); $c = new curl; $result = $c->download(array(array('url'=>$url, 'file'=>$fp))); // Close file handler. fclose($fp); if (empty($result)) { unlink($path); return null; } return array('path'=>$path, 'url'=>$url); }
/** * * @global object $CFG * @param string $photo_id * @param string $file * @return string */ public function get_file($photo_id, $file = '') { global $CFG; $result = $this->flickr->photos_getSizes($photo_id); $url = ''; if (!empty($result[4])) { $url = $result[4]['source']; } elseif (!empty($result[3])) { $url = $result[3]['source']; } elseif (!empty($result[2])) { $url = $result[2]['source']; } $path = $this->prepare_file($file); $fp = fopen($path, 'w'); $c = new curl(); $c->download(array(array('url' => $url, 'file' => $fp))); $watermark = get_config('flickr_public', 'watermark'); if (!empty($watermark)) { $img = new moodle_image($path); $img->watermark($url, array(10, 10), array('ttf' => true, 'fontsize' => 9))->saveas($path); } return $path; }
/** * Download a file, this function can be overridden by subclass. {@link curl} * * @param string $url the url of file * @param string $filename save location * @return string the location of the file */ public function get_file($url, $filename = '') { global $USER; $cookiename = uniqid('', true) . '.cookie'; $dir = make_temp_directory('repository/equella/' . $USER->id); $cookiepathname = $dir . '/' . $cookiename; $path = $this->prepare_file($filename); $fp = fopen($path, 'w'); $c = new curl(array('cookie'=>$cookiepathname)); $c->download(array(array('url'=>$url, 'file'=>$fp)), array('CURLOPT_FOLLOWLOCATION'=>true)); // Close file handler. fclose($fp); // Delete cookie jar. unlink($cookiepathname); return array('path'=>$path, 'url'=>$url); }
/** * Download a file from alfresco - do we use this? * * @param string $uuid a unique id of directory in alfresco * @param string $path path to a directory * @return array|null */ public function get_file($uuid, $file = '') { //error_log("get_file($uuid, '{$file}');"); $node = $this->elis_files->get_info($uuid); if (empty($node)) { return null; } // Test to make sure this works with, say, a teacher or someone non-admin $username = ''; /// Check for a non-text file type to just pass through to the end user. $mimetype = !empty($node->filemimetype) ? $node->filemimetype : ''; $ticket = elis_files_utils_get_ticket('refresh', $username); $url = str_replace($node->filename, urlencode($node->filename), $node->fileurl) . '?alf_ticket=' . $ticket; $path = $this->prepare_file($file); $fp = fopen($path, 'w'); $c = new curl; $response = $c->download(array(array('url'=>$url, 'file'=>$fp))); return array('path' => $path, 'url' => $url); }
/** * * @param string $photoid * @param string $file * @return string */ public function get_file($photoid, $file = '') { $url = $this->build_photo_url($photoid); $path = $this->prepare_file($file); $fp = fopen($path, 'w'); $c = new curl; $c->download(array( array('url'=>$url, 'file'=>$fp) )); fclose($fp); return array('path'=>$path, 'url'=>$url); }
public function get_file($uuid, $file = '') { global $CFG; $node = $this->sess->getNode($this->store, $uuid); $url = $this->get_url($node); $path = $this->prepare_file($file); $fp = fopen($path, 'w'); $c = new curl(); $c->download(array(array('url' => $url, 'file' => $fp))); return $path; }