在Drupal 8中可以使用$ _FILES吗?

时间:2018-07-27 23:34:35

标签: php drupal drupal-8

我正在尝试创建一个允许用户上传文件的表单。在大多数编程语言中,看起来似乎很简单,除了我在Drupal中这样做。

我从各种文档来源和无休止的搜寻时间中整理了以下内容:

  use Drupal\file\Entity\File;
  ...
  public function submitForm(array &$form, FormStateInterface $form_state) {
    // $file = file_get_contents($form_state->getValue('file'));
    $uploaded_file = File::load($form_state->getValue('file'));
    $file = File::load($uploaded_file[0]);
    $file->setPermanent();
    $file->save();
    $data = file_get_contents($file->getFileUri(), ',');
    drupal_set_message($data);

  }

但是我收到一条错误消息:

Error: Call to a member function setPermanent() on null in Drupal\JobFileUpload\Form\JobFileUploadForm->submitForm() 

这让我知道File :: load并未设置$ file变量

0 个答案:

没有答案
相关问题