adding files to file system repository programmatically

adding files to file system repository programmatically

by lital l -
Number of replies: 6

Hi,

I need to give my users an option to create directories and upload files to /var/www/moodledata/repository dir.

They need to do it from moodle site (can be from new page ), not from other program.

I tried to create new page with file picker, and when they press upload it should upload the file to the repository, but it didn't work.

Additionally, in this way they can't creat new directories in the repository.

How I can do it?

Thanks,

Lital



Average of ratings: -
In reply to lital l

Re: adding files to file system repository programmatically

by lital l -

Hi,

I will ask my question in other way...

How can I upload files to a file system repository from inside moodle?

I know there is no way to do it now and files must be uploaded to the folder on the server via FTP.

But how can I do it programmatically?


Thanks!



In reply to lital l

Re: adding files to file system repository programmatically

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Lital,

I'm unaware of a way to do what you are asking, unless you also come up with your own file handling code for it. Are you wanting this so that everyone has access to the files? If so you can already do that with the Folder resource, which by default the teacher manages the file structure and uploads, but students can access them for use. And if you REALLY want everyone to be able to change whats there by creating/deleting folders and uploading/accessing/deleting files, then go to the Administration > Permissions for the folder and add students to the Activity:Folder > Manage files in folder module setting.

This change will let any teacher or student in the Moodle course create folders and drag and drop files into the folders, including zipped files that contain subfolders. Just right click on a zip file and select Unzip.

The downside to this is that students can do things to the files and folders you might not want them to do, that can affect the experience of other users. If that is a problem, just use the Private files block instead which makes it so everyone is limited to and responsible for their own files.

In reply to AL Rachels

Re: adding files to file system repository programmatically

by lital l -

Hi AL Rachels,

Thanks for your answer.

I don't want that students will be able to upload files.

What I'm trying to do is to give access for coordinators in the course to upload files and create folders to the file system repository from Moodle site.

https://docs.moodle.org/29/en/File_system_repository 

In the documentetion you need to upload files directly to the server. 

We want to use this repository because, a lot of courses need the same files, and that way - you save the file only one time and everyone can access him and put it in his course. Another reason we want to use this, is load times. When we have a lots of files and imgs we suppose that link to the file will improve the load time of the course.

I create a new admin page with file picker but couldn't find a way to save the uploaded file in the file system repository.

Can you help me with the code of saving the file?

Thanks a lot!

In reply to lital l

Re: adding files to file system repository programmatically

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Lital,

At one time, I wanted to be able to to add files to the repository from in Moodle too, for the same reason you do, but gave up and just upload files directly to the server when I need to. I use WinSCP and transfer files via SFTP which lets me transfer whole folder systems and I can continue to work in Moodle while that's going on.

Before I retired from teaching, most of the files I needed to get into Moodle were pictures and videos from class and around the school. Since smart phone cameras have improved so much, I switched from using discrete video and photo cameras to using the one in my phone and had them automatically go to my Dropbox account. With Dropbox setup on all my computers, tablets, my phone, and my Moodle site, I seldom have to manually add files any more. Usually screen captures are the only thing I have to "do" anything with and that is to simply place the files into my desktop computer Dropbox and they show up in Moodle, shortly thereafter, just like any video or photo taken on my phone does.

In reply to AL Rachels

Re: adding files to file system repository programmatically

by lital l -

Hi,

My problem is that I don't have the files. 

Only the coordinators have them, and I don't want to be the one how upload them.

Thank for your reply!

In reply to lital l

Re: adding files to file system repository programmatically

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Then the easiest way probably would be to create a folder resource, give you coordinators permission to upload into the folder resource, and have them upload the files.