/** * 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::contentMimetype($contents), 'ContentLength' => Util::contentSize($contents))); if ($visibility = $config->get('visibility')) { $options['ACL'] = $visibility === AdapterInterface::VISIBILITY_PUBLIC ? 'public-read' : 'private'; } $this->client->putObject($options); if ($visibility) { $options['visibility'] = $visibility; } return $this->normalizeObject($options); }
public function getMimetype($path) { if (!($data = $this->read($path))) { return false; } $data['mimetype'] = Util::contentMimetype($data['contents']); return $data; }
/** * 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::contentMimetype($contents); $this->cache[$path]['mimetype'] = $mimetype; return $mimetype; }
/** * Update a file * * @param $path * @param $contents * @return array|bool */ public function update($path, $contents) { $location = $this->prefix($path); if (($size = file_put_contents($location, $contents, LOCK_EX)) === false) { return false; } return array('path' => $path, 'size' => $size, 'contents' => $contents, 'mimetype' => Util::contentMimetype($contents)); }