Moodle xml format can now export and import the actual image files, encoding

in 'base64' format.
This commit is contained in:
thepurpleblob
2006-04-21 12:35:57 +00:00
parent 2712ac665c
commit d08e16b2a5
2 changed files with 63 additions and 2 deletions
+33
View File
@@ -205,6 +205,39 @@ class qformat_default {
return true;
}
function importimagefile( $path, $base64 ) {
/// imports an image file encoded in base64 format
/// This should not be overridden.
global $CFG;
// all this to get the destination directory
// and filename!
$fullpath = "{$CFG->dataroot}/{$this->course->id}/$path";
$path_parts = pathinfo( $fullpath );
$destination = $path_parts['dirname'];
$file = clean_filename( $path_parts['basename'] );
// detect and fix any filename collision - get unique filename
$newfiles = resolve_filename_collisions( $destination, array($file) );
$newfile = $newfiles[0];
// convert and save file contents
if (!$content = base64_decode( $base64 )) {
return false;
}
$newfullpath = "$destination/$newfile";
if (!$fh = fopen( $newfullpath, 'w' )) {
return false;
}
if (!fwrite( $fh, $content )) {
return false;
}
fclose( $fh );
// return the (possibly) new filename
return $newfile;
}
// Export functions