Hey,
i'm actually working on the moodle file API.
i use the filepicker to upload file.
the files are stored lik this:
component : user
filearea : draft
author : name of the auther (not NULL)
for the same auther the file can downloaded but not for another user.
So these is my code :
view.php :
$file = $DB->get_record_sql('SELECT * FROM {files} WHERE filename <> "." and itemid = ?', array($video->pdflink));
$url2 = moodle_url::make_draftfile_url($file->itemid,'/', $file->filename);
echo'
<a href= '.$url2.'> Click to download ';
echo $file->filename;
echo'</a>
<br>
';
----------------
mod_form.php
$mform->addElement('filepicker', 'pdflink', get_string('file'), null, array('maxbytes' => $maxbytes, 'accepted_types' => '*'));
----------------
lib.php
function video_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options=array()) {
global $DB, $CFG;
if ($context->contextlevel != CONTEXT_MODULE) {
send_file_not_found();
}
require_login($course, true, $cm);
send_file_not_found();
}
thanks