You are here

public function FileFormField::setValue in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/dom-crawler/Field/FileFormField.php \Symfony\Component\DomCrawler\Field\FileFormField::setValue()

Sets the value of the field.

Parameters

string $value 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 53

Class

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

Namespace

Symfony\Component\DomCrawler\Field

Code

public function setValue($value) {
  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 = sys_get_temp_dir() . '/' . sha1(uniqid(mt_rand(), true));
    if (array_key_exists('extension', $info)) {
      $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 = array(
    'name' => $name,
    'type' => '',
    'tmp_name' => $value,
    'error' => $error,
    'size' => $size,
  );
}