Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FileFormField.php

function FileFormField::setValue

Sets the value of the field.

Overrides FormField::setValue

2 calls to FileFormField::setValue()
FileFormField::initialize in vendor/symfony/dom-crawler/Field/FileFormField.php
Initializes the form field.
FileFormField::upload in vendor/symfony/dom-crawler/Field/FileFormField.php
Sets the value of the field.

File

vendor/symfony/dom-crawler/Field/FileFormField.php, line 49

Class

FileFormField
FileFormField represents a file form field (an HTML file input tag).

Namespace

Symfony\Component\DomCrawler\Field

Code

public function setValue(?string $value) : void {
    if (null !== $value && is_readable($value)) {
        $error = \UPLOAD_ERR_OK;
        $size = filesize($value);
        $info = pathinfo($value);
        $name = $info['basename'];
        // copy to a tmp location
        $tmp = tempnam(sys_get_temp_dir(), $name);
        if (\array_key_exists('extension', $info)) {
            unlink($tmp);
            $tmp .= '.' . $info['extension'];
        }
        if (is_file($tmp)) {
            unlink($tmp);
        }
        copy($value, $tmp);
        $value = $tmp;
    }
    else {
        $error = \UPLOAD_ERR_NO_FILE;
        $size = 0;
        $name = '';
        $value = '';
    }
    $this->value = [
        'name' => $name,
        'type' => '',
        'tmp_name' => $value,
        'error' => $error,
        'size' => $size,
    ];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal