Attaches a file to a input field on the HTML.

@param   string $file        file name relative to mink definitions
@param   string $selector    CSS file upload element selector
760361
protected function attachFile($fileName, $selector)
    {
        if ($this->getMinkParameter('files_path')) {
            $fullPath = rtrim(
                realpath(
                    $this->getMinkParameter('files_path')
                ),
                DIRECTORY_SEPARATOR
            ) . DIRECTORY_SEPARATOR . $fileName;

            if (is_file($fullPath)) {
                $fileInput = 'input[type="file"]' . $selector;
                $field = $this->getSession()->getPage()->find('css', $fileInput);

                if (null === $field) {
                    throw new Exception("File input $selector is not found");
                }
                $field->attachFile($fullPath);
            }
        } else {
            throw new Exception("File $fileName is not found at the given location: $fullPath");
        }
    }
724868
public function writeFile($file, $content)
    {
        $this->ensureDir(dirname($file));

        file_put_contents($file, $content);
    }
280039
protected function addResourceFile(string $file): void
    {
        if (!is_file($file)) {
            throw new \InvalidArgumentException("$file is not a file");
        }
        
        $contents = file_get_contents($file);
        
        if ($contents === false) {
            throw new \RuntimeException("Error reading file at $file.");
        }
        
        $this->addResourceString($contents);
    }
973477
public function setFileInput($file, $mode = DATA_MANIPULATION_CREATE_MODE_AUTO, $extension = null)
    {
        $this->setFilename($file);
        if ($mode == DATA_MANIPULATION_CREATE_MODE_AUTO) {
            $mode = $this->getModeByFile($file, $extension);
        }
        if ($mode == DATA_MANIPULATION_CREATE_MODE_ODS) {
            $this->setCore(new CSVManipulator());
        } else if ($mode == DATA_MANIPULATION_CREATE_MODE_XLS) {
            $this->setCore(new XLSManipulator());
        } else if ($mode == DATA_MANIPULATION_CREATE_MODE_XLSX) {
            $this->setCore(new XLSXManipulator());
        } else {
            $this->setCore(new CSVManipulator());
        }
    }
739153
public function addElement($element) {
		if ($element instanceof HtmlButtongroups) {
			$this->elements []=$element;
		} else {
			$this->getLastButtonGroup()->addElement($element);
		}
	}
251718
public function appendSelector(FileSelector $selector)
    {
        if ($this->isReference()) {
            throw $this->noChildrenAllowed();
        }
        parent::appendSelector($selector);
    }
1260796
function(id, fileInput) {
                super_.add(id, {input: fileInput});

                fileInput.setAttribute("name", inputName);

                // remove file input from DOM
                if (fileInput.parentNode) {
                    qq(fileInput).remove();
                }
            }
720420
public function addFile($file, $strip = true)
    {
        $realfile = realpath($this->path . DIRECTORY_SEPARATOR . $file);
        $this->files[$file] = [$realfile, (bool) $strip];
    }
940973
function(file) {
		if (plupload.typeOf(file) === 'string') {
			file = this.getFile(file);
		}
		this.uploader.removeFile(file);
	}
248911
public function uploadSingle($file) {
        $storage = $this->storage;
        $finfo = new \finfo(FILEINFO_MIME_TYPE);
        $message = '';
        $filename = '';
        $original = strip_tags($file['name']);

        // Check finfo instance
        if (!$finfo) {
            exit('Magic database could not be created!');
        }

        try {
            // Check integrity of POST object
            if (!isset($file['error']) || is_array($file['error']) ) {
                throw new \RuntimeException('Invalid parameters!');
            }

            // Handle errors
            switch ($file['error']) {
            case UPLOAD_ERR_OK:
                break;
            case UPLOAD_ERR_NO_FILE:
                throw new \RuntimeException('No file sent!');
            case UPLOAD_ERR_INI_SIZE:
            case UPLOAD_ERR_FORM_SIZE:
                throw new \RuntimeException(
                    'Exceeded filesize limit! Maximum is 10MB.'
                );
            default:
                throw new \RuntimeException('Something happened.');
            }

            // Check file size
            if ($file['size'] < 200 || $file['size'] > 10000000) {
                throw new \RuntimeException('File too large. Maximum is 10MB.');
            }

             // Check file type
            if (false === $ext = array_search(
                $finfo->file($file['tmp_name']),
                array(
                    'pdf' => 'application/pdf',
                ),
                true
            )) {
                throw new \RuntimeException(
                    'Invalid file format. Only PDF files allowed.'
                );
            }

            // Try to move uploaded file
            $filename = sprintf(
                $storage . DIRECTORY_SEPARATOR . '%s.%s',
                sha1_file($file['tmp_name']),
                $ext
            );
            if (!move_uploaded_file(
                $file['tmp_name'],
                $filename
            )) {
                throw new \RuntimeException(
                    'Failed to move uploaded file. Contact webmaster.'
                );
            }

        } catch (\RuntimeException $e) {
            $message = $e->getMessage();
        }

        return ['original' => $original, 'filename' => $filename, 'message' => $message];

    }
973063
public function attachFile($xpath, $path) {
    if (!file_exists($path)) {
      throw new DriverException("Wow there the file does not exist, you can not upload it");
    }

    if (($realPath = realpath($path)) === false) {
      throw new DriverException("Wow there the file does not exist, you can not upload it");
    }

    $element = $this->findElement($xpath, 1);
    $tagName = $this->getTagName($xpath);
    if ($tagName != "input") {
      throw new DriverException("The element is not an input element, you can not attach a file to it");
    }

    $attributes = $this->getBrowser()->attributes($element["page_id"], $element["ids"][0]);
    if (!isset($attributes["type"]) || $attributes["type"] != "file") {
      throw new DriverException("The element is not an input file type element, you can not attach a file to it");
    }

    $this->browser->selectFile($element["page_id"], $element["ids"][0], $realPath);
  }
1302471
protected void setFileInput(CmsFileInput fileInput) {

        // only accept file inputs with a single selected file
        if (fileInput.getFiles().length == 1) {
            if (m_okButton != null) {
                m_okButton.enable();
            }
            if (m_fileInput != null) {
                m_fileInput.removeFromParent();
            }
            m_fileInput = fileInput;
            RootPanel.get().add(m_fileInput);
            m_mainPanel.setContainerWidget(createFileWidget(m_fileInput.getFiles()[0]));
        }
    }
1228623
function ($placeholder) {
			var that = this,
					$selectFile, files;

			$selectFile = $('<input type="file" multiple="multiple">').click();
			$selectFile.change(function () {
				files = this.files;
				that.uploadFiles($placeholder, files, that);
			});

			$.fn.mediumInsert.insert.deselect();

			return $selectFile;
		}
97897
protected function addUploadedFile($file)
    {
        $this->clear();

        $this->uploaded_file = $this->getFileManager()->make($file);

        // Get the original values
        $filename = $this->uploaded_file->getClientOriginalName();
        $content_type = $this->uploaded_file->getMimeType();

        // Set model values
        $this->instanceWrite('file_name', $filename);
        $this->instanceWrite('file_size', $this->uploaded_file->getSize());
        $this->instanceWrite('content_type', $content_type);
        $this->instanceWrite('updated_at', date('Y-m-d H:i:s'));
        $this->instanceWrite('queued_file', null);

        // Queue all styles for writing
        $this->setQueue('write', $this->styles);
    }
375065
public function save($selection = null)
	{
		// prepare the selection
		if (func_num_args())
		{
			if (is_array($selection))
			{
				$filter = array();

				foreach ($this->container as $file)
				{
					$match = true;
					foreach($selection as $item => $value)
					{
						if ($value != $file->{$item})
						{
							$match = false;
							break;
						}
					}

					$match and $filter[] = $file;
				}

				$selection = $filter;
			}
			else
			{
				$selection =  array($this[$selection]);
			}
		}
		else
		{
			$selection = $this->container;
		}

		// loop through all selected files
		foreach ($selection as $file)
		{
			$file->save();
		}
	}
505293
public static function createFile($file, $content = '')
    {
        $folder = dirname($file);
        if (!is_dir($folder)) {
            self::createFolder($folder);
        }

        file_put_contents($file, $content);
    }
1080398
protected function loadLayoutUpdate($file)
    {
        $update = $this->loader->load($file);
        if ($update) {
            $el = $update instanceof ElementDependentLayoutUpdateInterface
                ? $update->getElement()
                : 'root';
            $this->updates[$el][] = $update;

            $this->dependencyInitializer->initialize($update);
        }
    }