Sets uploaded file information (`$_FILES` array, better as
`$this->request->getData('file')`)
@param array $file Uploaded file information
@return \MeTools\Controller\Component\UploaderComponent
@uses setError()
@uses $error
@uses $file
347775
public function set($file)
    {
        //Resets `$error`
        unset($this->error);

        $this->file = (object)$file;

        //Errors messages
        $errors = [
            UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the maximum size that was specified in php.ini',
            UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the maximum size that was specified in the HTML form',
            UPLOAD_ERR_PARTIAL => 'The uploaded file was partially uploaded',
            UPLOAD_ERR_NO_FILE => 'No file was uploaded',
            UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder',
            UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk',
            UPLOAD_ERR_EXTENSION => 'File upload stopped by extension',
            'default' => 'Unknown upload error',
        ];

        //Checks errors during upload
        if (!isset($file['error']) || $file['error'] !== UPLOAD_ERR_OK) {
            //Gets the default error message, if the error can not be
            //  identified or if the key is not present
            if (!isset($file['error']) || !array_key_exists($file['error'], $errors)) {
                $file['error'] = 'default';
            }

            $this->setError($errors[$file['error']]);
        }

        return $this;
    }
552337
protected function setUploadedFiles(array $files)
    {
        $validate = function ($files) use (&$validate) {
            foreach ($files as $item) {
                if (is_array($item)) {
                    $validate($item);
                    continue;
                }
                if (! $item instanceof UploadedFileInterface) {
                    throw new InvalidArgumentException(
                        'Invalid structure of uploaded files provided.'
                    );
                }
            }
        };
        $validate($files);
        $this->uploadedFiles = $files;

        return $this;
    }
29980
public function setFile($file)
    {
        if (!is_file($file)) {
            throw new \InvalidArgumentException('File not found: '.$file, ErrorCodes::FILE_NOT_FOUND);
        }
        if (!is_readable($file)) {
            throw new \InvalidArgumentException('File is not readable: '.$file, ErrorCodes::FILE_NOT_READABLE);
        }
        $this->file = $file;
        return $this;
    }
888943
protected static function setFile($file)
    {
        if (self::$isCom === false) {
            $incFile = route()->views.'/'.$file.'.php';
            if (file_exists($incFile)) {
                self::$file = $incFile;
            }
        } else {
            $incFile = route()->com.$file.'.php';
            if (file_exists($incFile)) {
                self::$file = $incFile;
            }
        }
    }
1335134
public function uploadImg($file)
    {
        return $this->auth(function () use ($file) {
            $http = $this->http([
                'method' => 'post',
                'dataType' => 'json',
                'timeout' => 30000,
                'url' => $this->baseUrl . 'cgi-bin/media/uploadimg?access_token=' . $this->accessToken,
                'files' => [
                    'media' => $file,
                ],
            ]);

            return $http;
        });
    }
1157222
public function setFile($file)
    {

        //Return false if file does not exists;
        if (!$this->isFile($file)) {
            return false;
        }
        //Get the file info
        $this->file = $file;
        $this->pathinfo[$file] = pathinfo($file);

        //Return an instance of the file object;
        return $this;
    }
536797
public function toFile($file)
    {
        $composer = json_decode(file_get_contents($file), true);

        // Remove the zendframework/zendframework
        unset($composer['require']['zendframework/zendframework']);

        // Add all the found components
        foreach (array_keys($this->components) as $component) {
            $composer['require']['zendframework/' . $component] = $this->version;
        }

        file_put_contents($file, json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
    }
1351261
public function addFile($file) {
        $baseName = basename($file, '.php');

        $components = explode('.', $baseName);
        $language = $components[1];

        $data = require($file);

        $this->add($data, $language);
    }
775468
public static function createUploadedFile(
        $file,
        $size = null,
        $error = UPLOAD_ERR_OK,
        $clientFilename = null,
        $clientMediaType = null
    ) {
        if (! static::$uploadedFileFactory) {
            static::$uploadedFileFactory = new UploadedFileFactory();
        }

        return static::$uploadedFileFactory->createUploadedFile(
            $file,
            $size,
            $error,
            $clientFilename,
            $clientMediaType
        );
    }
577066
protected function _setCurrentFile($file)
    {
        $this->_currentFile = $file .((!is_link($file) && is_dir($file) && substr($file, -1) != DS) ? DS : '');
        return $this;
    }
151118
protected function handleChunkFile($file)
    {
        // Move the uploaded file to chunk folder
        $this->file->move($this->getChunkDirectory(true), $this->chunkFileName);

        return $this;
    }
1208441
private function convertFile(array $file)
    {
        if (!isset($file['name']) || !isset($file['type']) || !isset($file['tmp_name']) || !isset($file['error']) || !isset($file['size'])) {
            return null;
        }

        if (is_array($file['error'])) {
            $result = [];
            foreach ($file['error'] as $key => $error) {
                $result[$key] = $this->convertFile([
                    'name'     => $file['name'][$key],
                    'type'     => $file['type'][$key],
                    'tmp_name' => $file['tmp_name'][$key],
                    'error'    => $file['error'][$key],
                    'size'     => $file['size'][$key],
                ]);
            }
        }
        else {
            $result = new \Core\Services\UploadedFile($file['tmp_name'], $file['name'], $file['error']);
        }

        return $result;
    }
764168
protected function customiseFile(File $file)
    {
        $customizedfile = $file->customise(array(
            'UploadFieldThumbnailURL' => $this->getThumbnailURLForFile($file),
            'UploadFieldDeleteLink' => $this->getItemHandler($file->ID)->DeleteLink(),
            'UploadFieldEditLink' => $this->getItemHandler($file->ID)->EditLink(),
            'UploadField' => $this
        ));

        // render file buttons
        return $customizedfile->customise(array(
                'UploadFieldFileButtons' => (string) $file->renderWith($this->getTemplateFileButtons(), array(
                    'IconRemove' => $this->IconRemove(),
                    'IconEdit' => $this->IconEdit(),
                    'EditEnabled' => $this->EditEnabled(),
                ))
        ));
    }
1338231
protected function convertFileInformation($file)
    {
        if ($file instanceof UploadedFile) {
            return $file;
        }

        $file = $this->fixPhpFilesArray($file);
        if (\is_array($file)) {
            $keys = array_keys($file);
            sort($keys);

            if ($keys == self::$fileKeys) {
                if (UPLOAD_ERR_NO_FILE == $file['error']) {
                    $file = null;
                } else {
                    $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['error']);
                }
            } else {
                $file = array_map([$this, 'convertFileInformation'], $file);
                if (array_keys($keys) === $keys) {
                    $file = array_filter($file);
                }
            }
        }

        return $file;
    }
998445
private function uploadOne(UploadedFile $file)
    {
        try {
            $uploader = new Uploader(['config' => $this->_config]);
            $uploader->up($file);
            $fileInfo = $uploader->getFileInfo();
            $result = [
                'name' => Html::encode($file->name),
                'url' => $fileInfo['url'],
                'path' => $fileInfo['url'],
                'extension' => $file->extension,
                'type' => $file->type,
                'size' => $file->size
            ];
            if ($this->onlyImage !== true) {
                $result['filename'] = $result['name'];
            }

        } catch (Exception $e) {
            $result = [
                'error' => $e->getMessage()
            ];
        }
        return $result;
    }
558924
public function setFiles($file, $name = null)
	{
		// Verifying if is array
		if (is_array($file)) {
			foreach ($file as $k => $v) {
				$this->setFiles($v,$k);
			}
		} else {
			$parray = &$this->files;
			
			if (file_exists($file)) {
				if (is_null($file)) {
					if (isset($parray[$name])) unset($parray[$name]);
				} else {
					if (is_null($name) || is_integer($name)) {
						$count = count($parray);
						$name = 'file_contents_' . $count;
					}
						
					$parray[$name] = $file;
				}
			} else {
				throw new RuntimeException('Invalid file, file not exists.');
			}	
		}
		
		return $this;
	}
1164404
public function load($file)
    {
        if (!is_string($file) || !file_exists($file)) {
            throw new InvalidArgumentException('File must be a valid file.');
        }

        $data = include $file;

        if (!is_array($data)) {
            throw new RuntimeException('File did not return an array.');
        }

        return $this->set($data);
    }