Webiny\Component\Http\Request\Files::get PHP Method

get() public method

If you have a multi-dimensional upload field name, than you should pass the optional $arrayOffset param to get the right File object.
public get ( string $name, null | integer $arrayOffset = null ) : File
$name string Name of the upload field.
$arrayOffset null | integer Optional array offset for multi-dimensional upload fields.
return Webiny\Component\Http\Request\Files\File
    public function get($name, $arrayOffset = null)
    {
        // first some validations
        if (!$this->fileBag->keyExists($name)) {
            throw new FilesException('Upload field with name "' . $name . '" was not found in the $_FILES array.');
        }
        // check to see if we have already created the file object
        if (isset($this->fileObject[$name])) {
            $fileObject = $this->getFileObject($name, $arrayOffset);
            if ($fileObject) {
                return $fileObject;
            }
        }
        // create and return File object
        $file = $this->fileBag->key($name);
        if (is_null($arrayOffset)) {
            $fileObject = $this->createFileObject($file, $arrayOffset);
            return $fileObject;
        } else {
            if (!isset($file['name'][$arrayOffset])) {
                throw new FilesException('Uploaded file with name "' . $name . '" and
											offset "' . $arrayOffset . '" was not found in the $_FILES array.');
            }
            $fileObject = $this->createFileObject($file, $arrayOffset);
            return $fileObject;
        }
    }

Usage Example

Example #1
0
 /**
  * Get the File object for the given $name.
  * If you have a multi-dimensional upload field name, than you should pass the optional $arrayOffset param to get the
  * right File object.
  *
  * @param string   $name        Name of the upload field.
  * @param null|int $arrayOffset Optional array offset for multi-dimensional upload fields.
  *
  * @throws \Exception|Request\Files\FilesException
  * @return Files\File
  */
 public function files($name, $arrayOffset = null)
 {
     try {
         return $this->files->get($name, $arrayOffset);
     } catch (Files\FilesException $e) {
         throw $e;
     }
 }
All Usage Examples Of Webiny\Component\Http\Request\Files::get