protected function store_file_for_text_field(&$text, $tempdir, $filepathinsidetempdir, $filename) {
        global $USER;
        $fs = get_file_storage();
        if (empty($text['itemid'])) {
            $text['itemid'] = file_get_unused_draft_itemid();
        }
        // As question file areas don't support subdirs,
        // convert path to filename.
        // So that images with same name can be imported.
        $newfilename = clean_param(str_replace('/', '__', $filepathinsidetempdir . '__' . $filename), PARAM_FILE);
        $filerecord = array(
            'contextid' => context_user::instance($USER->id)->id,
            'component' => 'user',
            'filearea'  => 'draft',
            'itemid'    => $text['itemid'],
            'filepath'  => '/',
            'filename'  => $newfilename,
        );
        $fs->create_file_from_pathname($filerecord, $tempdir . '/' . $filepathinsidetempdir . '/' . $filename);
        return $newfilename;
    }
protected function store_file_for_text_field(&$text, $tempdir, $filepathinsidetempdir, $filename) {
        global $USER;
        $fs = get_file_storage();
        if (empty($text['itemid'])) {
            $text['itemid'] = file_get_unused_draft_itemid();
        }
        // As question file areas don't support subdirs,
        // convert path to filename.
        // So that images with same name can be imported.
        $newfilename = clean_param(str_replace('/', '__', $filepathinsidetempdir . '__' . $filename), PARAM_FILE);
        $filerecord = array(
            'contextid' => context_user::instance($USER->id)->id,
            'component' => 'user',
            'filearea'  => 'draft',
            'itemid'    => $text['itemid'],
            'filepath'  => '/',
            'filename'  => $newfilename,
        );
        $fs->create_file_from_pathname($filerecord, $tempdir . '/' . $filepathinsidetempdir . '/' . $filename);
        return $newfilename;
    }
protected function store_file_for_text_field ( & $ text , $ tempdir , $ filepathinsidetempdir , $ filename ) { global $ USER ; $ fs = get_file_storage ( ) ; if ( empty ( $ text [ 'itemid' ] ) ) { $ text [ 'itemid' ] = file_get_unused_draft_itemid ( ) ; } // As question file areas don't support subdirs, // convert path to filename. // So that images with same name can be imported. $ newfilename = clean_param ( str_replace ( '/' , '__' , $ filepathinsidetempdir . '__' . $ filename ) , PARAM_FILE ) ; $ filerecord = array ( 'contextid' => context_user :: instance ( $ USER -> id ) -> id , 'component' => 'user' , 'filearea' => 'draft' , 'itemid' => $ text [ 'itemid' ] , 'filepath' => '/' , 'filename' => $ newfilename , ) ; $ fs -> create_file_from_pathname ( $ filerecord , $ tempdir . '/' . $ filepathinsidetempdir . '/' . $ filename ) ; return $ newfilename ; }
Store an image file in a draft filearea
@param array $text, if itemid element don't exists it will be created
@param string $tempdir path to root of image tree
@param string $filepathinsidetempdir path to image in the tree
@param string $filename image's name
@return string new name of the image as it was stored
Store an image file in a draft filearea