wwwroot/pluginfile.php/$forumcontextid/mod_forum/post/$postid/image.jpg // Prepare file record object //$targetPath = $CFG->dataroot.'/'.SITEID.'/presenter/'.(int)$_GET["moduleId"].'/'; $filename = str_replace(' ', '_', $_FILES['Filedata']['name']); $fileinfo = new SplFileInfo($filename); $extension = $fileinfo->getExtension(); $allowable = array('jpg', 'gif', 'png', 'mov', 'mpg'); //get the extension of the file being uploaded $fileext = strtolower($extension); if (!in_array($fileext, $allowable)) { echo "This $filename file is not allowed."; exit(); } //$context = get_context_instance(CONTEXT_MODULE, $cmid); $context = context_module::instance($cmid); $contextid = $context->id; $fileinfo = array( 'contextid' => $contextid, // ID of context 'component' => 'mod_sloodle', // usually = table name 'filearea' => 'presenter', // usually = table name 'itemid' => $itemid, // usually = ID of row in table // 'filepath' => '/presenter', // any path beginning and ending in / 'filepath' => '/'.$contextid.'/mod_sloodle/presenter/'.$itemid.'/', 'filename' => $filename ); $tmpfilename = $_FILES['Filedata']['tmp_name'] ; $fs->create_file_from_pathname( $fileinfo, $tmpfilename); echo 1; } // else { if (!empty($_FILES)) { // $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $CFG->dataroot.'/'.SITEID.'/'.$cmid.'/sloodle/presenter/'; $targetFile = str_replace('//','/',$targetPath) . str_replace(' ','_',$_FILES['Filedata']['name']); $fileinfo = new SplFileInfo($targetFile); $extension = $fileinfo->getExtension(); //Server side security check //only allow images!!! //$allowable = array ('.jpg','.gif','.png','.htm','.html','.mov'); $allowable = array('jpg', 'gif', 'png', 'mov', 'mpg'); //get the extension of the file being uploaded $fileext = strtolower($extension); if (!in_array($fileext, $allowable)) { echo "This file is not allowed."; exit(); } mkdir(str_replace('//','/',$targetPath), 0755, true); move_uploaded_file($tempFile,$targetFile); echo 1; // TODO: Change this to echo file path } }