file upload custom form - drupal 8

function file_save_upload
这个函数依然存在啊
=============================
$validators = array( 'file_validate_extensions' => array('pdf'), ); $form['my_file'] = array( '#type' => 'managed_file', '#name' => 'my_file', '#title' => t('File *'), '#size' => 20, '#description' => t('PDF format only'), '#upload_validators' => $validators, '#upload_location' => 'public://my_files/', );
--
here is a bug
https://www.drupal.org/project/drupal/issues/2884052

-----

use Drupal\file\Entity\File;

  $fid = $form_state->getValue(['test_CERTIFICATE', 0]);
  if (!empty($fid)) {
    $file = File::load($fid);
    $file->setPermanent();
    $file->save();
  }

---------------
You could check for an existing file with the same name before you make the temporary file permanent. – 4k4 Jul

posted @ 2018-04-02 09:35  qqisnow2021  阅读(123)  评论(0编辑  收藏  举报