Adding SQL code on a blank Moodle page

Re: Adding SQL code on a blank Moodle page

by Ambrish Tiwari -
Number of replies: 0

Hi Lebato

Creating files directly in the DB is bound to get you into strife - especially as we add layers of caching etc. 

Use the file_storage class to create your files:

$fs = get_file_storage();

$pathtofile = '/tmp/blah.txt';

$record = new stdClass();
$record->contextid = ???;
$record->component = ???;
$record->filearea = ???;
$record->itemid = ???;
$record->filepath = ???;

$fs->create_file_from_pathname($record, $pathtofile);

 

Another way is to create a "File system" repository and just upload the files to the configured folder on your server.