filename; } /** * Sets the new filename where the content will be stored * * @param string $filename (Optional) New filename to set * @return self */ public function setFilename($filename = null) { $this->filename = $filename; return $this; } /** * Defined by Zend\Filter\Filter * * Encrypts the file $value with the defined settings * * @param string|array $value Full path of file to change or $_FILES data array * @return string|array The filename which has been set, or false when there were errors * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException */ public function filter($value) { // An uploaded file? Retrieve the 'tmp_name' $isFileUpload = (is_array($value) && isset($value['tmp_name'])); if ($isFileUpload) { $uploadData = $value; $value = $value['tmp_name']; } if (!file_exists($value)) { throw new Exception\InvalidArgumentException("File '$value' not found"); } if (!isset($this->filename)) { $this->filename = $value; } if (file_exists($this->filename) and !is_writable($this->filename)) { throw new Exception\RuntimeException("File '{$this->filename}' is not writable"); } $content = file_get_contents($value); if (!$content) { throw new Exception\RuntimeException("Problem while reading file '$value'"); } $encrypted = parent::filter($content); $result = file_put_contents($this->filename, $encrypted); if (!$result) { throw new Exception\RuntimeException("Problem while writing file '{$this->filename}'"); } if ($isFileUpload) { $uploadData['tmp_name'] = $this->filename; return $uploadData; } return $this->filename; } }