Problems with repositories and the file system

Problems with repositories and the file system

by Bruno Dias -
Number of replies: 0

Greetings.

So...im trying to create simple text files, in a repository instance.

Im doing it like it is being shown in the File API tutorial. But, the problem is that, after creating it, if i navigate through the repository, i can't find the file!!! In fact, the file is stored within the filedir directory, in moodledata. And, as far as i can see, the file isn't associated with the repository instance because, for example, when i use the filepicker again, in the same course, i can't find that file!

 

this is my code:

 

$fs = get_file_storage();
$context = get_context_instance(CONTEXT_MODULE, $webcast->course);

// Prepare file record object
$fileinfo = array(
'contextid' => $context->id, // ID of context
'component' => 'webcast', // usually = table name
'filearea' => 'd1_rep', // usually = table name
'itemid' => 0, // usually = ID of row in table
'filepath' => '/', // any path beginning and ending in /
'filename' => 'myfile.txt'); // any filename

// Create file containing text 'hello world'
$fs->create_file_from_string($fileinfo, 'hello world 2');

 

Another problem that is bothering me is that, when i choose a file, in the filepicker, that it's located within the repository directory, in moodledata, moodle copies the entire file to the filedir directory. Seriously, why?? It's like wasting disk space for the sake of...i don't even know...

 

Im tired of running through the documentation just to accomplish small things, within this system. I could even complain and argue about the architecture and other things but that's material for other topics.

Average of ratings: -