diff --git a/mod/data/preset.php b/mod/data/preset.php
index 29fe961ab17..66f0e0e0184 100644
--- a/mod/data/preset.php
+++ b/mod/data/preset.php
@@ -187,19 +187,20 @@ switch ($action) {
if (!data_submitted() or !confirm_sesskey()) {
print_error('invalidrequest');
}
+ $exportfile = data_presets_export($course, $cm, $data);
+ $downloadsubdir = "$course->id/moddata/data/$data->id";
+ $filename = clean_filename($data->name . '-preset-' . gmdate("Ymd_Hi") . '.zip');
+ $downloadfile = "$CFG->dataroot/$downloadsubdir/$filename";
+ @unlink($downloadfile);
- echo '
';
- $file = data_presets_export($course, $cm, $data);
- echo get_string('exportedtozip', 'data')."
";
- $perminantfile = $CFG->dataroot."/$course->id/moddata/data/$data->id/preset.zip";
- @unlink($perminantfile);
- /* is this created elsewhere? sometimes its not present... */
- make_upload_directory("$course->id/moddata/data/$data->id");
-
- /* now just move the zip into this folder to allow a nice download */
- if (!rename($file, $perminantfile))
+ // Move the exported zip to the download folder
+ make_upload_directory($downloadsubdir);
+ if (! rename($exportfile, $downloadfile)) {
print_error('cannotmovezip');
- echo "
".get_string('download', 'data')."";
+ }
+ echo '
';
break;