Get hold of a file being uploaded as a resource

Get hold of a file being uploaded as a resource

by Daniel Mannarino -
Number of replies: 1

Hello!

What I really want to do is take an action on every file being uploaded as a resource. To this end I am modifying mod/resource/lib.php:resource_add_instance

However I am having trouble getting hold of the file. I'm still new to this, but after reading a lot of docs and code I tried adding

$fs = get_file_storage();
$context = context_module::instance($cmid);
$files = $fs->get_area_files($context->id, 'mod_resource', 'files');
However I'm afraid I can't get get_area_files to yield anything but a 0-length array. I also tried 'content' instead of 'files' for the file area, to no avail.

I see some things being done in resource_set_mainfile that, IIUC, saves the just-uploaded file from tthe draft files area to a permanent location, and I tried placing my new lines both before and after its invocation. Still nothing.

Can anyone tell me what I am doing wrong, or at least how it should be done?

Thanks in advance!


Average of ratings: -