function fetchRealUrl($moduleid, $courseid, $itemid, $filearea, $filepath, $requestid) { global $PAGE, $DB; //new return values array $return = fetchReturnArray(false); //fetch info and ids about the module calling this data $course = $DB->get_record('course', array('id' => $courseid)); $modinfo = get_fast_modinfo($course); //get component info //may be able to avoid useing moduleid, by using PAGE global $cm = $modinfo->get_cm($moduleid); //$cm=$PAGE->cm; $component = "mod_" . $cm->modname; //get module context //may be able to avoid useing moduleid, by using PAGE global $thecontext = get_context_instance(CONTEXT_MODULE, $moduleid); //$thecontext=$PAGE->context; //FIlter could submit submission/draft/content/intro as options here if ($filearea == "") { $filearea = "content"; } //establish our filename $filename = poodllBasename($filepath); //There is probably a better way to do this, that doesnt hang on multipbyte //need to remove filename and leave trailing dir sep $filepath = strrev(strstr(strrev($filepath), DIRECTORY_SEPARATOR)); //get the file brower object $browser = get_file_browser(); //fetch our info object $fileinfo = $browser->get_file_info($thecontext, $component, $filearea, $itemid, $filepath, $filename); //get the url to the file if ($fileinfo) { $urltofile = $fileinfo->get_url(); } else { $urltofile = "accessdenied"; } //prepare our return array $return['success'] = false; array_push($return['messages'], "we have a url"); array_push($return['messages'], $filepath . " " . $filename); //array_push($return['messages'],$thecontext->id . " " . $component . " " . $filearea . " " . $itemid . " " . $filepath . " " . $filename); array_push($return['messages'], $urltofile); //Return the data $xml_output = prepareXMLReturn($return, $requestid); return $xml_output; }
function instance_download($mimetype, $filename, $filehash, $requestid) { //paramone=mimetype paramtwo=filename paramthree=filehash requestid, header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment;filename='" . $filename . "'"); header("Content-Type: " . $mimetype); header("Content-Transfer-Encoding: binary"); //header('Accept-Ranges: bytes'); $fs = get_file_storage(); $f = $fs->get_file_by_hash($filehash); if ($f) { //$content = $f->get_content(); //echo $content; $f->readfile(); } else { //set up return object $return = fetchReturnArray(false); array_push($return['messages'], "file not found."); $xml_output = prepareXMLReturn($return, $requestid); header("Content-type: text/xml"); echo "<?xml version=\"1.0\"?>\n"; echo $xml_output; return; } }