From: jerome Date: Wed, 29 Oct 2008 08:20:12 +0000 (+0000) Subject: MDL-15351: the plugin didn't retrieve any file. The problem was cause by the curl... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=b953d4a4594e32fa5c551d6463e82b3d844cd625;p=moodle.git MDL-15351: the plugin didn't retrieve any file. The problem was cause by the curl download function that can not have session => now we deal with fileinfo parameters, not the file url. --- diff --git a/repository/local/repository.class.php b/repository/local/repository.class.php index dfe599bd82..8e0d50224c 100755 --- a/repository/local/repository.class.php +++ b/repository/local/repository.class.php @@ -208,11 +208,14 @@ class repository_local extends repository { if ($search && (stristr($filename, $search) === false)) { continue; } + $params = $child->get_params(); + $source = serialize(array($params['contextid'], $params['filearea'], $params['itemid'], $params['filepath'], $params['filename'])); $list[] = array( 'title' => $filename, 'size' => $filesize, 'date' => $filedate, - 'source' => $child->get_url(), + //'source' => $child->get_url(), + 'source' => base64_encode($source), 'thumbnail' => $CFG->pixpath .'/f/'. mimeinfo_from_type("icon", $filetype) ); $filecount++; @@ -222,6 +225,48 @@ class repository_local extends repository { return $filecount; } + /** + * Download a file, this function can be overridden by + * subclass. + * + * @global object $CFG + * @param string $url the url of file + * @param string $file save location + * @return string the location of the file + * @see curl package + */ + public function get_file($url, $file = '') { + global $CFG; + if (!file_exists($CFG->dataroot.'/temp/download')) { + mkdir($CFG->dataroot.'/temp/download/', 0777, true); + } + if (is_dir($CFG->dataroot.'/temp/download')) { + $dir = $CFG->dataroot.'/temp/download/'; + } + if (empty($file)) { + $file = uniqid('repo').'_'.time().'.tmp'; + } + if (file_exists($dir.$file)) { + $file = uniqid('m').$file; + } + + ///retrieve the file + $fileparams = unserialize(base64_decode($url)); + $contextid = $fileparams[0]; + $filearea = $fileparams[1]; + $itemid = $fileparams[2]; + $filepath = $fileparams[3]; + $filename = $fileparams[4]; + $fs = get_file_storage(); + $sf = $fs->get_file($contextid, $filearea, $itemid, $filepath, $filename); + $contents = $sf->get_content(); + $fp = fopen($dir.$file, 'w'); + fwrite($fp,$contents); + fclose($fp); + + return $dir.$file; + } + /** * */