How to share files between courses

How to share files between courses

by Ronaldo Reis Jr. -
Number of replies: 47
Hi,

how is the best way to share some files between some courses?

I try to make this using a metacourse extructure, but it is not transparent. Files in metacourse is not showed in a child course's file management.

Any suggestion?

Thanks
Ronaldo
Average of ratings: -
In reply to Ronaldo Reis Jr.

Re: How to share files between courses

by Thomas Robb -
The simplest way to make files available to any course is to place them in the "site files" area (administration/server/files) but this is a non-secure location that contains a warning, "Files that are placed here can be accessed by anyone".

The only way that it will work with a metacourse is to place the files that you want to be accessible to both courses in the meta-course itself. Anyone who is registered in any child of the meta-course should then be able to access them.

If you want people to be able to access the files directly from the child courses, you can, after creating the file instance in the meta-course, take the URL of the instance (from the address line after clicking on it to make it appear) and place that URL as the URL of a "file or web site" in each child. Of course, it might be simpler just to upload the file into each site if you have to go through so much work!

Of course, if you know what shared files you will need before the courses are set up, you can create a course with all of the files set up with links on the course page, and then save & restore that course to the other courses you need to create. After that, you can individualize each course with other material.
In reply to Ronaldo Reis Jr.

Re: How to share files between courses

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hello,

Unfortunately there is at the moment no single user-friendly solution for sharing resources (not just files) across courses in Moodle. This is for me the most serious flaw in Moodle. I am satisfied with none of the solutions that are proposed whenever this "sharing of resources" question crops up (which is quite frequently).

Some solutions require that you have admin rights, which is not the case of teachers who work in large institutions. Other solutions rely on the meta-courses, which are not easy to manipulate. And yet other solutions rely on your courses being completely written and static at the beginning of the year, which is not my conception of online courses. For instance, at the moment I have about half a dozen of Glossaries with overlapping entries in half a dozen courses. Whenever I update one entry in one course I have to update it in all of the other courses.

What I would very much like to see is a teacher repository, where I would upload all of the files I need in my various courses (html, pdg, images, glossaries, etc.). Whenever I need to use one of those resources I would simply link to it from any of my own courses. Whenever I would need to update one of those resources it would be automatically updated in all of my courses where it is being used.

Unfortunately I have come to the conclusion that the present architecture of Moodle prevents this solution from being implemented - for the time being at least.

Joseph

In reply to Joseph Rézeau

Re: How to share files between courses

by Sean S -
I'm with Joseph on this one.
In reply to Joseph Rézeau

Re: How to share files between courses

by John Isner -
I also agree with Joseph.

The problem with the Site files solution is the lack of transparency, as pointed out by the original poster.

One possible solution to the lack-of-transparency problem would be for Moodle to add an "up one level" folder icon named "Site files" to the Files area of each course. This is probably dangerous. For example, teachers without editing privileges in course 1 would now be able to add, delete, and modify files.

A safer solution would be for Moodle to inject links to individual site files into the course files listing of each course, the same (elegant) way the question database injects links to published categories into the category listings of local question databases. Since these files are truly SHARED across all courses, they would be read-only in the listing (no way to delete, move, edit, or rename).

For example, below is a course files listing for course 2. The course itself has three files and site files has three files. The files happen to have the same names. However Moodle has disambiguated the names by adding the suffix (Site files).

a.txt
b.html
c.zip
a.txt (Site files)
b.html (Site files)
c.zip (Site files)
In reply to Joseph Rézeau

Re: How to share files between courses

by Art Lader -
Joseph,

You hit the nail on the head there. Wish I had the money to make it happen!

Regards,
Art
In reply to Joseph Rézeau

Re: How to share files between courses

by Cory B -
I agree with Joseph on this one. Our teachers would really like a way to share files, quizzes, etc. between their different courses.
In reply to Ronaldo Reis Jr.

Re: How to share files between courses

by Ronaldo Reis Jr. -
Hi all,

I try to use Myfiles, but installation fail.

I think that solution is not hard to implement. I think that is only put in code an instruction for each child course look at metacourse directory in the file choose window or make a link in child's file manager point to metacourse's file manager. I'm not a good programmer, but it look like an easy task.

Anyone is able to make a patch to this?

Thanks
Inte
Ronaldo
In reply to Ronaldo Reis Jr.

Re: How to share files between courses

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Ronaldo > I'm not a good programmer, but it look like an easy task.

I'm not a good programmer either, but I know what I want is not an easy task. If it were it would have been implemented a long time ago.wink

Joseph

In reply to Joseph Rézeau

Re: How to share files between courses

by Alexander Harmsen -
Dear all,

Joseph you have hit the nail on the head. Now how can we make the following happen:

What I would very much like to see is a teacher repository, where I would upload all of the files I need in my various courses (html, pdg, images, glossaries, etc.). Whenever I need to use one of those resources I would simply link to it from any of my own courses. Whenever I would need to update one of those resources it would be automatically updated in all of my courses where it is being used.

Our in house programmer is more than willing to help. We are possibly going to impliment a work-around but it is very inelegant as it requires coding in the server itself for every new course.

How about some of us collaborating to make these capabilities a reality.

How does one bring such an issue to those in charge at moodle?


In reply to Alexander Harmsen

Re: How to share files between courses

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Alexander > How does one bring such an issue to those in charge at moodle?

Way to go is to post a bug report (it will be called a new feature, in fact) in the Moodle Tracker. My programing skills prevent me from helping in this venture but I am keen to carry out tests, should individuals or teams embark on this venture.

Joseph

Attachment image00.jpg
In reply to Alexander Harmsen

Re: How to share files between courses

by John Isner -
I suggested the following solution in another discussion. I'm repeating it here with some embellishments. It creates the kind of teacher repository that Alexander is asking for. You need the cooperation of your Moodle admin to set it up. It can be set up manually (I have a small site, so that's how I did it), or it can be automated with a script that the admin runs when a new course is created, or it can be done by modifying the Moodle source code. Here's how to do it manually:

The admin, using the shell, creates a subdirectory of moodledata/1 ("Site Files") for each teacher. On my (linux) system, this would be

cd /var/moodledata/1
mkdir Harmsen Isner Rezeau


The admin then creates a symbolic link in the moodledata subdirectory for each course. Let's say Harmsen teaches courses 2, 3, 4, Isner teaches 5, 6, 7, and Rezeau teaches 8, 9, 10. Again, on my system:

cd /var/moodledata
ln -s 1/Harmsen 2/MySiteFiles
ln -s 1/
Harmsen 3/MySiteFiles
ln -s 1/Harmsen 4/MySiteFiles
ln -s 1/Isner 5/MySiteFiles
ln -s 1/
Isner 6/MySiteFiles
ln -s 1/Isner 7/MySiteFiles
ln -s 1/Rezeau 8/MySiteFiles
ln -s 1/
Rezeau 9/MySiteFiles
ln -s 1/Rezeau 10/MySiteFiles

Now within each of his courses, a teacher will see a folder named "MySiteFiles" in the Files area (Administration -> Files). Any files he uploads something into this directory, it will be seen in all his other courses.

The files will be backed up with course 1 as well as with each of the individual course backups. Warning: since files uploaded to here are in site files, "they can be accessed by anyone" so you don't store any sensitive material.
In reply to John Isner

Re: How to share files between courses

by Travis Sobeck -
I have implemented a similar tactic to create a repository in a sense. The php file that creates the new course has a minor addition to create a symbolic link to a folder that holds all the files. (The code is at work, but if people are interested I can post it Thursday. You have to be aware of permissions though depending on where the source folder is. Apache has to have access and you may have to modify SELinux as well.
Truly a DMS (Document Management System) would be preferable if you have the ambition.
In reply to Travis Sobeck

Re: How to share files between courses

by Alexander Harmsen -
It would be fantastic if you would post the details about how to automate the symbolic link creation process, including your knowlege about permissions requirements.

Our goal is to allow a new course to be created with the symbolic link already in place to our "global content" folder. In addition, if this "global content" folder could be excluded from the individual course backups, this would be the ideal solution which would satisfy our needs until the proposed Repository API solution becomes availiable.

In reply to Alexander Harmsen

Re: How to share files between courses

by Travis Sobeck -
Added the ability to create a symlink whenever a new course directory is created (the first time it is accessed).

Two variables for config.php :
$CFG->repositorydir
:: points to the directory that the repository is contained in.
$CFG->repositorypointer
:: is the name of the symlink pointing to that directory.

Then update file: <moodleRoot>/lib/setuplib.php
look for the function "make_upload_directory($directroy, $shownotices=true){

towards the end of the functions you will see:
foreach ($dirarray as $dir) {
$currdir = $currdir .'/'. $dir;
if (! file_exists($currdir)) {
if (! mkdir($currdir, $CFG->directorypermissions)) {
if ($shownotices) {
echo '<div class="notifyproblem" align="center">ERROR: Could not find or create a directory ('.
$currdir .')</div>'."<br />\n";
}
return false;
}
//add the following here
else {
if( !empty($CFG->repositorydir) && !empty($CFG->repositorypointer) ) {
if (count($dirarray) == 1) { /* We're creating a root directory */
/* Add check for windows here, symlink will die if it's under windows, maybe add shell command for junction under windows? */
if (!symlink($CFG->repositorydir.'/', $CFG->dataroot.'/'.$dir.'/'.$CFG->repositorypointer)) {
echo 'Symlink has failed!';
}
}
}
}
////
As for permissions, you have multiple layers. At the files system layer, the webserver needs read/write access to the repository (so on linux you define apache to run as a user/group then give that user/group access to the repository). Then the webserver has to allow that particular site read/write. So for apache you modify httpd.conf and use the <Directory> tag.



In reply to Travis Sobeck

Re: How to share files between courses

by John Isner -
Nice, I like it! But what about the interaction of backup/restore with symlinks? Moodle does not backup symlinks. It makes copies of the files pointed to by the symlinks. After a course with symlinks is restored from backup, it will have local copies of all the files that were formerly shared. So anyone who uses symlinks for sharing should be aware backup/restore breaks sharing.
In reply to John Isner

Re: How to share files between courses

by Peter Campbell -
John - does this mean that the file is uploaded once and then other courses that use this file point to this file? Or does it mean that the file is uploaded to one course and then duplicated in the other courses that use it?

I would also like to see teachers be able to upload a file one time in one place and, if they change it, only have to change it once so that the changes will show up everywhere the file is referenced.

Does your work-around accomplish this?

Peter
In reply to Peter Campbell

Re: How to share files between courses

by John Isner -
The files are shared, not copied. Copying is evil!
In reply to John Isner

Re: How to share files between courses

by John Isner -
There is a potentially backup/restore problem with my scheme. When Moodle backs up the indivual courses, it compresses and stores the files referred to by symbolic links, rather than backing up the symbolic link itself. So if you restore your course from a backup, you will get a copy of the file, which is probably not what you want. To backup the symbolic link, you could experiment with adding the -y option to the zip command options -- if you can find it smile -- in Moodle's backup logic.
In reply to John Isner

Re: How to share files between courses

by Peter Campbell -
OK - that sounds good! So the file is uploaded once in one place, correct? Then it shows up in all courses, correct? Ideally, I'd like to control where it shows up. In other words, I'd like to put everything in one place and then point to the file from the courses where I want it to appear. Does your scheme allow for this?
In reply to Peter Campbell

Re: How to share files between courses

by John Isner -
So the file is uploaded once in one place, correct?

yes

Then it shows up in all courses, correct?

yes

Ideally, I'd like to control where it shows up. In other words, I'd like to put everything in one place and then point to the file from the courses where I want it to appear. Does your scheme allow for this?

yes

----------

If you have a fairly dynamic site, consider using Travis Sobeck's automated solution rather than my manual solution. Be aware that with either method you will end up with copies of your "shared files" in a restored course if the course contains symbolic links (I don't think this is a real problem).

In reply to John Isner

Re: How to share files between courses

by Tim Allen -
I have used your strategy in the past. I will tell you why it is not ideal for me.

Be aware that with either method you will end up with copies of your "shared files" in a restored course if the course contains symbolic links (I don't think this is a real problem).

This can be a real deal-breaker in a large site, because backups of the course each include a full copy of the shared files, which can fill up a hard disk very quickly when there are many courses.

Warning: since files uploaded to here are in site files, "they can be accessed by anyone" so you don't store any sensitive material.

This is a major security problem and unacceptable for a large, live site where files need to be kept for course users only.

I was able to use a similar strategy, instead using a symbolic link to the files area of another course rather than to the site files. Unfortunately, this no longer works, someone must have changed the code for stronger security.

So now the metacourses are the only way to go. There are two problems with this approach:

1. As mentioned above, the files are not "transparent", so to link to one from a child course you need to go and get the correct link from the metacourse and then paste it in to the former, which is a lot of work.
2. Files from the metacourse used at the site level are not accessible.

It really is a headache in Moodle to share files between courses. sad
In reply to Tim Allen

Re: How to share files between courses

by John Isner -
It really is a headache in Moodle to share files between courses.

You can say that again. sad. I agree completely with your assessment of this solution.

It would be nice if Moodle backup/restore respected symbolic links.

In reply to John Isner

Re: How to share files between courses

by John Isner -
I just created an issue MDL-9036 "Backup/restore should respect symbolic links." Let's see what happens smile
In reply to John Isner

Re: How to share files between courses

by John Isner -
Negative on MDL-9036 ("difficult to implement"), but it sounds like the core team is working on a better overall solution to file sharing.
In reply to John Isner

Re: How to share files between courses

by Tim Allen -
Thanks for that John, I have added a comment over there - I am sure that your suggestion is a stopgap measure but to me the "better overall solution" that you mention doesn't sound close at all, from the comments of Petr there. sad

So it would still be nice if that could be implemented - and I didn't understand Eloy's comment about why it could not be done, so I just thought I would try and clarify it.

By the way, you could try putting the symbolic link in the 'backupdata' folder, because files in there are not included in backups. That worked for me in the past, although I haven't tested it recently (and I am not that interested in symbolic links any more because they only seem to work with files stored in the insecure site files area). Anyway, if this still works then the bug you created may not be so important any more. wink

Tim.


In reply to Tim Allen

Re: How to share files between courses

by John Isner -
Hi Tim,
I already commented on the brilliance of your 'backupdata' idea in the bug report!
In reply to Peter Campbell

Re: How to share files between courses

by Ronaldo Reis Jr. -
Ok all,

this thread sound like a born of a new module.

Unfortunately,

For now, I don't have easy access to server to test all possible solutions, but I read all messages.

By
Ronaldo
In reply to Ronaldo Reis Jr.

Re: How to share files between courses

by chris dennison -

I wonder if there are areas of overlap between this requirement and the e-portfolio requirement we have approaching here in the UK.  We are using moodle within our secondary school for on-line courses and also on-line examinations.

For non-moodle applications like Word etc. I use  windows (server 2003) scripts to tailor user logon's to point to their appropriate repositories (using mapped drives)  A users own space is the Y: drive for example. 

Backup of this type of repository is easily automated outside moodle. 

I think there may be security issues of apache reaching across the internal network...and restore from backup might not be straight foreward.

In reply to chris dennison

Re: How to share files between courses

by Wesley Wakeman -

This is very similar to what I'd like to have done. We don't have the same issues as you can't use our moodle site unless you are a user of the school network so no-one can get to the site files area without already having access internally.

Wes

In reply to Wesley Wakeman

Re: How to share files between courses

by Wesley Wakeman -

Travis I've just added the code you've suggested to the Moodle setup we've got but it doesn't seem to be doing anything is there anything else I have to do within the moodle code to activate this? We're currently using Moodle 1.7.1+ (2006101011).

Wes 

In reply to Wesley Wakeman

Re: How to share files between courses

by Wesley Wakeman -

I've managed to do it manually I'd like to get the automatic php working but I'm happy enough for now I'll re-write the php then I'll give you a heads up.

Wes

In reply to Wesley Wakeman

Re: How to share files between courses

by Sean S -
I also want this to work but not as a hack. I really see this as fundemental functionality, but alas it has yet to happen.
In reply to Ronaldo Reis Jr.

Re: How to share files between courses

by Jonathan Simons -

Hi - I have just started to set up a MOODLE at this college and I really need to share files for the structure I want. It seems to me that it would all be fine if I could use, say, a Maths Meta-course to hold common files for all the other individual maths courses. I was disappointed to find that after putting files into the meta-course I could not access them from the child-course. I was looking for the folder for the meta-course in the child file structure - but it wasn't there.

This is going to be very awkward......

Jonathan

In reply to Jonathan Simons

Re: How to share files between courses

by Eric Hagley -
If it is just quizzes you are wanting to share can you not go to the "edit categories" in the "edit quiz" section (right side of the screen toward the top) and click on the eye to "publish" the quiz. This allows others to access the quizzes in other courses is my understanding.
Not sure if this is what you are talking about.
Eric
Average of ratings: Useful (1)
In reply to Eric Hagley

Re: How to share files between courses

by John Isner -
Yes, questions in published categories are shared. But this discussion is about sharing files and resources, not questions.

To illustrate the difference, suppose you create a question that you want to share with other teachers. You publish the category. Now other teachers can see your question.

But suppose your question contains an image located in your course files area. Other teachers who are using your question will see a broken link where the image should be. This is because the question is shared but the image is not.

Moodle does not offer a good way to share images and other files among courses. You can always copy them, but copying is not sharing.
In reply to Eric Hagley

Re: How to share files between courses

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Hi everyone,
I too would like to see a comprehensive solution to sharing content among courses without having to copy it. Until that is possible though, we have to find workarounds.

One workaround which I have used, and which has been suggested earlier on this thread, is symbolic links from the course directory back to a central directory. Symbolic links are not normally available on Windows servers, but they can be simulated using NTFS-link

It is easiest to create symbolic links using SSH (Secure Shell), but even if you do not have Shell access, you can sometimes write a little PHP script to create the symbolic link for you. For example, the script below creates a link from the course whose id is "99" back to a central shared folder:

<?php
$courseid = '99';
$to = '/home/sharedfiles';
$from = "/home/moodledata/$courseid/sharedfiles";

print
"Creating a symbolic link to $to from $from ... ";
if (symlink( $to, $from )) {
print '<font color="green">OK</font><br />';
} else {
print '<font color="red">FAILED</font><br />';
}
?>

In the above script, you will need to set the $courseid and the $to and $from paths, to what you need in your situation. Save the script as "symlink.php", up load it to your server and then run it by typing its URL into your browser.

Once the symbolic link is set, you (and your students) have free access to files and folders in the shared folder.

Watch out when you delete the course though. The standard Moodle delete scripts are not expecting symbolic links and will go and delete all the files in folder in the shared folder! Yikes! surprise

You can modify the standard Moodle scripts to detect symbolic links and act accordingly as follows:

moodle/lib/filelib.php (around line 512)

OLD:
if (is_dir($location)) {

NEW:
if (is_link($location)) {
if (!unlink($location)) {
return false;
}
} else if (is_dir($location)) {

You may need to change some modules as well. For example, I worked on a site that used scorm activities a lot, so we had to make the delete function in the scorm module aware of symbolic links too:

moodle/mod/scorm/locallib.php (around line 74)

OLD:
if (is_dir($directory)) {

NEW:
if (is_link($directory)) {
return unlink($directory);
} else if (is_dir($directory)) {

As has been noted earlier, if you choose to backup course files when making backups of courses with symbolic links such as I have described above, then the entire shared folder will be backed up for each course which links to it. Probably you don't want this. Tim's idea of putting the links within the course "backupdata" seems a good way to get round this.

hope this helps someone smile
Gordon
Average of ratings: Useful (2)
In reply to Gordon Bateson

Re: How to share files between courses

by Roger Emery -
Hi Gordon,

Your code above is very useful.
We see three uses
- to link to centralised store of commonly used images (thumbnails, uni images, logos etc)
- to link to a central shared video folder (we process all video to flv - would make the admin of this a lot easier!)
- to allow tutors to share their own common content among their various courses.

However the identified issue with back-up saving everything is a real problem. If I put the shared folder in backupdata it will not be an obvious place for tutors to look when using the image editor etc, although this is a good workaround

Would anyone be able to advise on code to add to the backup.php to unlink symbolic linked folders to prevent back-up - maybe similar the delete work around?

Many Thanks
Roger
In reply to Ronaldo Reis Jr.

Re: How to share files between courses

by John Isner -
New issue created: MDL-9134 "Need a good solution to the problem of sharing files and resources among courses" Please vote.
In reply to John Isner

Re: How to share files between courses

by Michael Boardman -
How about (this is TOTALY insecure BTW) just edit file.php to NOT require a course login to view whatever type of file you need.

I did this for images to allow sharing of images between courses.

Michael Boardman
mboardman@atlanta.k12.ga.us
In reply to Michael Boardman

Re: How to share files between courses

by John Isner -
It sounds like a reasonable workaround for images, except possibly for user profile images (you'll definitely get objections there). Perhaps this could be a site configuration option. True, it is insecure, but successful exploitation requires that a valid file name is known or can be guessed. The Moodle File system already has a similar vulnerability, and not too many people worry about it -- see this discussion.
In reply to Ronaldo Reis Jr.

Re: How to share files between courses

by Marcus Hoberg -

Has anybody here experiences in using DOOR (Digital Open Pbject Repository) for the shared files issue? It provides a direct PlugIn to the moodle "Add a resource" menu, and seems to run on the same environment. The only additional software needed is cURL library.

http://sourceforge.net/projects/door/

http://curl.haxx.se/

Marcus

In reply to Marcus Hoberg

Re: How to share files between courses

by Oswel Morales -
How it works this DOOR thing??? Im not good with PHP (no idea about programming).
I looked on the web a site about the "official open metamod". Havent used it, but i look around and ill tell you about it.
In reply to Marcus Hoberg

Ynt: Re: How to share files between courses

by Metin ÇELİKBAŞ -

Would you please explain step by step how to overcome the issue with DOOR. I'm novice in moodle.  smile Thanks.