Development:Using the File API: Difference between revisions
From MoodleDocs
No edit summary |
|||
Line 23: | Line 23: | ||
For example, if you have just built a file at the path | For example, if you have just built a file at the path | ||
$from_zip_file = $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/".$preferences->backup_name; | $from_zip_file = | ||
$CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/".$preferences->backup_name; | |||
And you want to move it into the course_backup file area, do | And you want to move it into the course_backup file area, do |
Revision as of 05:34, 2 February 2009
Template:Moodle 2.0 The file API is for managing all the files stored by Moodle. If you are interested in how the file API works internally, see Development:File_API. The page is just about what you need to know to use the file API. Related is the Development:Repository API, which lets users get files into Moodle.
Overview of how it works
File areas
Serving files to users
Getting files from the user
Getting a file from a Moodle form
Getting a file with content from the HTML editor
Giving a file to the user
Moving files around
For example, if you have just built a file at the path
$from_zip_file = $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/".$preferences->backup_name;
And you want to move it into the course_backup file area, do
$context = get_context_instance(CONTEXT_COURSE, $preferences->backup_course); $fs = get_file_storage(); $file_record = array('contextid'=>$context->id, 'filearea'=>'course_backup', 'itemid'=>0, 'filepath'=>'/', 'filename'=>$preferences->backup_name, 'timecreated'=>time(), 'timemodified'=>time()); $fs->create_file_from_pathname($file_record, $from_zip_file);
See also
- Development:File_API how the File API works internally.
- Moodle 2.0 roadmap