/** * @return int The number of bytes written to the file. * @param mixed $data THe data to be written to the file. * @param int $flags FILE_APPEND | LOCK_EX (FILE_TEXT | FILE_BINARY only for PHP 6) * @throws EyeBadMethodCallException * @throws EyeIOException */ public function putContents($data, $flags = 0) { if (!is_integer($flags)) { throw new EyeInvalidArgumentException('Expecting an integer value for $flags. Given: "' . $flags . '" (' . gettype($flags) . ').'); } $opts = array('ftp' => array('overwrite' => true)); $context = stream_context_create($opts); try { $this->destroyConnection(); $bytesAdded = file_put_contents($this->path, $data, $flags, $context); } catch (Exception $e) { throw new EyeIOException('Error occured during data transfer to file ' . AdvancedPathLib::getURLForDisplay($this->path) . '.', 0, $e); } catch (ErrorException $e) { throw new EyeIOException('Error occured during data transfer to file ' . AdvancedPathLib::getURLForDisplay($this->path) . '.', 0, $e); } if ($bytesAdded === false) { throw new EyeIOException('Unable to write data to file ' . AdvancedPathLib::getURLForDisplay($this->path) . '.'); } if ($flags & FILE_APPEND) { $this->statsCache['size'] += $bytesAdded; } else { $this->statsCache['size'] = $bytesAdded; } $this->statsCache['isDirectory'] = false; return $bytesAdded; }