original_string: function save_stored_file($elname, $newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath='/',
                                $newfilename=null, $overwrite=false, $newuserid=null) {
          global $USER;
  
          if (!$this->is_submitted() or !$this->is_validated()) {
              return false;
          }
  
          if (empty($newuserid)) {
              $newuserid = $USER->id;
          }
  
          $element = $this->_form->getElement($elname);
          $fs = get_file_storage();
  
          if ($element instanceof MoodleQuickForm_filepicker) {
              $values = $this->_form->exportValues($elname);
              if (empty($values[$elname])) {
                  return false;
              }
              $draftid = $values[$elname];
              $context = context_user::instance($USER->id);
              if (!$files = $fs->get_area_files($context->id, 'user' ,'draft', $draftid, 'id DESC', false)) {
                  return false;
              }
              $file = reset($files);
              if (is_null($newfilename)) {
                  $newfilename = $file->get_filename();
              }
  
              if ($overwrite) {
                  if ($oldfile = $fs->get_file($newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath, $newfilename)) {
                      if (!$oldfile->delete()) {
                          return false;
                      }
                  }
              }
  
              $file_record = array('contextid'=>$newcontextid, 'component'=>$newcomponent, 'filearea'=>$newfilearea, 'itemid'=>$newitemid,
                                   'filepath'=>$newfilepath, 'filename'=>$newfilename, 'userid'=>$newuserid);
              return $fs->create_file_from_storedfile($file_record, $file);
  
          } else if (isset($_FILES[$elname])) {
              $filename = is_null($newfilename) ? $_FILES[$elname]['name'] : $newfilename;
  
              if ($overwrite) {
                  if ($oldfile = $fs->get_file($newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath, $newfilename)) {
                      if (!$oldfile->delete()) {
                          return false;
                      }
                  }
              }
  
              $file_record = array('contextid'=>$newcontextid, 'component'=>$newcomponent, 'filearea'=>$newfilearea, 'itemid'=>$newitemid,
                                   'filepath'=>$newfilepath, 'filename'=>$newfilename, 'userid'=>$newuserid);
              return $fs->create_file_from_pathname($file_record, $_FILES[$elname]['tmp_name']);
          }
  
          return false;
      }
code: function save_stored_file($elname, $newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath='/',
                                $newfilename=null, $overwrite=false, $newuserid=null) {
          global $USER;
  
          if (!$this->is_submitted() or !$this->is_validated()) {
              return false;
          }
  
          if (empty($newuserid)) {
              $newuserid = $USER->id;
          }
  
          $element = $this->_form->getElement($elname);
          $fs = get_file_storage();
  
          if ($element instanceof MoodleQuickForm_filepicker) {
              $values = $this->_form->exportValues($elname);
              if (empty($values[$elname])) {
                  return false;
              }
              $draftid = $values[$elname];
              $context = context_user::instance($USER->id);
              if (!$files = $fs->get_area_files($context->id, 'user' ,'draft', $draftid, 'id DESC', false)) {
                  return false;
              }
              $file = reset($files);
              if (is_null($newfilename)) {
                  $newfilename = $file->get_filename();
              }
  
              if ($overwrite) {
                  if ($oldfile = $fs->get_file($newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath, $newfilename)) {
                      if (!$oldfile->delete()) {
                          return false;
                      }
                  }
              }
  
              $file_record = array('contextid'=>$newcontextid, 'component'=>$newcomponent, 'filearea'=>$newfilearea, 'itemid'=>$newitemid,
                                   'filepath'=>$newfilepath, 'filename'=>$newfilename, 'userid'=>$newuserid);
              return $fs->create_file_from_storedfile($file_record, $file);
  
          } else if (isset($_FILES[$elname])) {
              $filename = is_null($newfilename) ? $_FILES[$elname]['name'] : $newfilename;
  
              if ($overwrite) {
                  if ($oldfile = $fs->get_file($newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath, $newfilename)) {
                      if (!$oldfile->delete()) {
                          return false;
                      }
                  }
              }
  
              $file_record = array('contextid'=>$newcontextid, 'component'=>$newcomponent, 'filearea'=>$newfilearea, 'itemid'=>$newitemid,
                                   'filepath'=>$newfilepath, 'filename'=>$newfilename, 'userid'=>$newuserid);
              return $fs->create_file_from_pathname($file_record, $_FILES[$elname]['tmp_name']);
          }
  
          return false;
      }
code_tokens: function save_stored_file ( $ elname , $ newcontextid , $ newcomponent , $ newfilearea , $ newitemid , $ newfilepath = '/' , $ newfilename = null , $ overwrite = false , $ newuserid = null ) { global $ USER ; if ( ! $ this -> is_submitted ( ) or ! $ this -> is_validated ( ) ) { return false ; } if ( empty ( $ newuserid ) ) { $ newuserid = $ USER -> id ; } $ element = $ this -> _form -> getElement ( $ elname ) ; $ fs = get_file_storage ( ) ; if ( $ element instanceof MoodleQuickForm_filepicker ) { $ values = $ this -> _form -> exportValues ( $ elname ) ; if ( empty ( $ values [ $ elname ] ) ) { return false ; } $ draftid = $ values [ $ elname ] ; $ context = context_user :: instance ( $ USER -> id ) ; if ( ! $ files = $ fs -> get_area_files ( $ context -> id , 'user' , 'draft' , $ draftid , 'id DESC' , false ) ) { return false ; } $ file = reset ( $ files ) ; if ( is_null ( $ newfilename ) ) { $ newfilename = $ file -> get_filename ( ) ; } if ( $ overwrite ) { if ( $ oldfile = $ fs -> get_file ( $ newcontextid , $ newcomponent , $ newfilearea , $ newitemid , $ newfilepath , $ newfilename ) ) { if ( ! $ oldfile -> delete ( ) ) { return false ; } } } $ file_record = array ( 'contextid' => $ newcontextid , 'component' => $ newcomponent , 'filearea' => $ newfilearea , 'itemid' => $ newitemid , 'filepath' => $ newfilepath , 'filename' => $ newfilename , 'userid' => $ newuserid ) ; return $ fs -> create_file_from_storedfile ( $ file_record , $ file ) ; } else if ( isset ( $ _FILES [ $ elname ] ) ) { $ filename = is_null ( $ newfilename ) ? $ _FILES [ $ elname ] [ 'name' ] : $ newfilename ; if ( $ overwrite ) { if ( $ oldfile = $ fs -> get_file ( $ newcontextid , $ newcomponent , $ newfilearea , $ newitemid , $ newfilepath , $ newfilename ) ) { if ( ! $ oldfile -> delete ( ) ) { return false ; } } } $ file_record = array ( 'contextid' => $ newcontextid , 'component' => $ newcomponent , 'filearea' => $ newfilearea , 'itemid' => $ newitemid , 'filepath' => $ newfilepath , 'filename' => $ newfilename , 'userid' => $ newuserid ) ; return $ fs -> create_file_from_pathname ( $ file_record , $ _FILES [ $ elname ] [ 'tmp_name' ] ) ; } return false ; }
docstring: Save file to local filesystem pool
  
  @param string $elname name of element
  @param int $newcontextid id of context
  @param string $newcomponent name of the component
  @param string $newfilearea name of file area
  @param int $newitemid item id
  @param string $newfilepath path of file where it get stored
  @param string $newfilename use specified filename, if not specified name of uploaded file used
  @param bool $overwrite overwrite file if exists
  @param int $newuserid new userid if required
  @return mixed stored_file object or false if error; may throw exception if duplicate found
docstring_tokens: Save file to local filesystem pool