Buenas fbedia88, te explico desde el principio.
Tengo una función que hace:
Código:
$content = $mform1->get_file_content('userfile');
donde userfile se coge de:
Código:
$mform->addElement('filepicker', 'userfile', get_string('file'));
Lo que yo quiero es que
userfile sea un fichero que el programa coja un fichero almacenado en el servidor y no un archivo que se seleccione por el filepicker.
Para ello quiero sustituir la variable userfile por una variable del tipo a la que voy a usar en esa función.
Sabes cómo hacerlo??
Gracias!!.
Código de get_file_content:
Código:
function get_file_content($elname) {
global $USER;
if (!$this->is_submitted() or !$this->is_validated()) {
return false;
}
$element = $this->_form->getElement($elname);
if ($element instanceof MoodleQuickForm_filepicker || $element instanceof MoodleQuickForm_filemanager) {
$values = $this->_form->exportValues($elname);
if (empty($values[$elname])) {
return false;
}
$draftid = $values[$elname];
$fs = get_file_storage();
$context = get_context_instance(CONTEXT_USER, $USER->id);
if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) {
return false;
}
$file = reset($files);
return $file->get_content();
} else if (isset($_FILES[$elname])) {
return file_get_contents($_FILES[$elname]['tmp_name']);
}
return false;
}