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\FieldCode
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,
];
}