4 This plugin intercepts some of the binary handling functions to
5 store uploaded files (as is) into a dedicated directory.
6 Because the ewiki database abstraction layer was not designed to
7 hold large files (because it reads records in one chunk), you may need
8 to use this, else large files may break.
10 WARNING: this is actually a hack and not a database layer extension,
11 so it will only work with the ewiki.php script itself. The database
12 administration tools are not aware of this agreement and therefor
13 cannot (for example) backup the externally stored data files!
14 If you later choose to disable this extension, the uploaded (and thus
15 externally stored) files then cannot be accessed any longer, of course.
17 - You must load this plugin __before__ the main script, because the
18 binary stuff in ewiki.php always engages automatically.
19 - The store directory can be the same as for dbff (filenames differ).
20 - All the administration tools/ are not aware of this hack, so __you__
21 must take care, when it comes to creating backups.
26 define("EWIKI_DB_STORE_DIRECTORY", "/tmp"); // where to save binary files
27 define("EWIKI_DB_STORE_MINSIZE", 0); // send smaller files into db
28 define("EWIKI_DB_STORE_MAXSIZE", 32 <<20); // 32MB max per file (but
29 // there is actually no way to upload such large files via HTTP)
31 # define("EWIKI_DB_STORE_URL", "http://example.com/wiki/files/store/");
32 // allows clients to directly access stored plain data files,
33 // without redirection through ewiki.php, RTFM
37 $ewiki_plugins["binary_store"][] = "moodle_binary_store_file";
38 $ewiki_plugins["binary_get"][] = "moodle_binary_store_get_file";
41 function moodle_binary_get_path($id, $meta, $course, $wiki, $userid, $groupid) {
43 $entry=wiki_get_entry($wiki, $course, $userid, $groupid);
45 error("Cannot get entry.");
48 $dir=make_upload_directory("$course->id/$CFG->moddata/wiki/$wiki->id/$entry->id/".$meta["section"]);
49 if(substr($id, 0, strlen(EWIKI_IDF_INTERNAL
))!=EWIKI_IDF_INTERNAL
) {
50 error("Binary entry does not start with ".EWIKI_IDF_INTERNAL
.substr($id, 0, strlen(EWIKI_IDF_INTERNAL
)));
52 $id = substr($id,strlen(EWIKI_IDF_INTERNAL
));
53 $id = clean_filename($id);
60 function moodle_binary_store_file(&$filename, &$id, &$meta, $ext=".bin") {
62 global $_FILES, $CFG, $course, $wiki, $groupid, $userid, $ewiki_title, $cm;
63 if(!$wiki->ewikiacceptbinary
) {
64 error("This wiki does not accept binaries");
69 $entry=wiki_get_entry($wiki, $course, $userid, $groupid);
71 error("Cannot get entry.");
74 require_once($CFG->dirroot
.'/lib/uploadlib.php');
75 $um = new upload_manager('upload',false,false,$course,false,0,true,true);
76 if ($um->process_file_uploads("$course->id/$CFG->moddata/wiki/$wiki->id/$entry->id/$ewiki_title")) {
77 $filename = ''; // this to make sure we don't keep processing in the parent function
79 $newfilename = $um->get_new_filename();
80 $id = EWIKI_IDF_INTERNAL
.$newfilename;
84 error($um->print_upload_log(true));
91 function moodle_binary_store_get_file($id, &$meta) {
93 global $CFG, $cm, $course, $wiki, $groupid, $userid;
96 if(!$wiki->ewikiacceptbinary
) {
97 error("This wiki does not accept binaries");
102 $filepath=moodle_binary_get_path($id, $meta, $course, $wiki, $userid, $groupid);
103 if (file_exists($filepath)) {
109 //$dbfname = EWIKI_DB_STORE_DIRECTORY."/".rawurlencode($id);
110 //if (file_exists($dbfname)) {
111 // readfile($dbfname);