Managing file upload - Help needed

Managing file upload - Help needed

by Marinko Pešo -
Number of replies: 6

Hey everyone,

I'm completely new to Moodle and I'm kinda trying to develop a simple modul to get into it all. Had PHP experience, not much but enough, still this system and its "size" confuses me a bit  smile

This may have been asked by somebody before, I Googled and Googled for hours but didn't find an answer I could understand, so I apologize from start to be asking a dumb question like this...
My problem is that I'm trying to add a file upload to my module so that for example teacher could upload a file as part of a bigger task and that file could be viewed by students. Now I tryed to look at similiar modules but simply could not find my way ... problem is, I have no clue how to fetch the file, save it, and display it ... all I managed to dig out from documentation so far was the upload function in mform:

$mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
$mform->addRule('attachment', null, 'required');

Now if somebody can help me where to go from here in order to actually get that file, and save it so I can display it in the module?
Any suggestions are really appreciated!

Average of ratings: -
In reply to Marinko Pešo

Re: Managing file upload - Help needed

by Marinko Pešo -

I solved it kinda manually, grabbing the temp file, saving it and doing all process via my own functions so it kinda works now...
Still I know this isn't in the "spirit" of Moodle programming so I'm still opened for any ideas regarding how to do this using Moodle functions instead of my own.

In reply to Marinko Pešo

Re: Managing file upload - Help needed

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Here's the relevant document:

Using_the_File_API_in_Moodle_forms

Yes it does work - yes it's difficult.

Good luck...

--sam

In reply to sam marshall

Re: Managing file upload - Help needed

by Glenys Hanson -

Errrr Sam, are you sure that's the page you meant to link to? thoughtful

Cheers,

Glenys

Attachment screenshot_01.png
In reply to Glenys Hanson

Re: Managing file upload - Help needed

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

sorry, at the time docs.moodle.org was dead so I wasn't able to actually test the link. Tim has given the correct one, thanks smile

--sam

In reply to sam marshall

Re: Managing file upload - Help needed

by Marinko Pešo -

Now this is something that looks helpfull ,and I didn't Google it so far  :D

Tnx a lot guys!!!!!  tongueout