/** * Write a file * * @param string $path * @param string $contents * @param mixed $config * @return array file metadata */ public function write($path, $contents, $config = null) { $config = Util::ensureConfig($config); $options = $this->getOptions($path, array('Body' => $contents, 'ContentType' => Util::guessMimeType($path, $contents), 'ContentLength' => Util::contentSize($contents)), $config); $result = $this->client->putObject($options); if ($result === false) { return false; } return $this->normalizeObject($options); }
/** * Retrieve the mimetype of an object * * @param string $path * @return null|string mimetype or null on failure */ public function getMimetype($path) { if (isset($this->cache[$path]['mimetype'])) { return $this->cache[$path]['mimetype']; } if (!($contents = $this->read($path))) { return false; } $mimetype = Util::guessMimeType($path, $contents); $this->cache[$path]['mimetype'] = $mimetype; return $mimetype; }
public function getMimetype($path) { if (!($data = $this->read($path))) { return false; } $data['mimetype'] = Util::guessMimeType($path, $data['contents']); return $data; }
/** * Update a file * * @param string $path * @param string $contents * @param mixed $config Config object or visibility setting * @return array|bool */ public function update($path, $contents, $config = null) { $location = $this->prefix($path); $mimetype = Util::guessMimeType($path, $contents); if (($size = file_put_contents($location, $contents, LOCK_EX)) === false) { return false; } return compact('path', 'size', 'contents', 'mimetype'); }