本文整理汇总了PHP中League\Flysystem\FilesystemInterface::putStream方法的典型用法代码示例。如果您正苦于以下问题:PHP FilesystemInterface::putStream方法的具体用法?PHP FilesystemInterface::putStream怎么用?PHP FilesystemInterface::putStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\FilesystemInterface
的用法示例。
在下文中一共展示了FilesystemInterface::putStream方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: put
/**
* Write the contents of a file.
*
* @param string $path
* @param string|resource $contents
* @param string $visibility
*
* @return bool
*/
public function put($path, $contents, $visibility = null)
{
$config = ['visibility' => $this->parseVisibility($visibility)];
if (is_resource($contents)) {
return $this->driver->putStream($path, $contents, $config);
}
return $this->driver->put($path, $contents, $config);
}
示例2: write
/**
* @inheritdoc
*/
public function write($path, SplFileInfo $file)
{
$stream = fopen($file->getRealPath(), 'r+');
$result = $this->filesystem->putStream($path, $stream);
if (is_resource($stream)) {
fclose($stream);
}
return $result;
}
示例3: writeFile
/**
* @param $filePath
* @param $content
*/
protected function writeFile($filePath, $content)
{
if (is_resource($content)) {
$result = $this->filesystem->putStream($filePath, $content);
} else {
$result = $this->filesystem->put($filePath, $content);
}
if (!$result) {
throw new SaveResourceErrorException('File cannot be written to the path ' . $filePath);
}
}
示例4: put
/**
* Write the contents of a file.
*
* @param string $path
* @param string|resource $contents
* @param array $options
* @return bool
*/
public function put($path, $contents, $options = [])
{
if (is_string($options)) {
$options = ['visibility' => $options];
}
if ($contents instanceof File || $contents instanceof UploadedFile) {
return $this->putFile($path, $contents, $options);
}
if (is_resource($contents)) {
return $this->driver->putStream($path, $contents, $options);
} else {
return $this->driver->put($path, $contents, $options);
}
}
示例5: put
/**
* Write the contents of a file.
*
* @param string $path
* @param string|resource $contents
* @param string $visibility
* @return bool
*/
public function put($path, $contents, $visibility = null)
{
if ($contents instanceof File || $contents instanceof UploadedFile) {
return $this->putFile($path, $contents, $visibility);
}
if ($visibility = $this->parseVisibility($visibility)) {
$config = ['visibility' => $visibility];
} else {
$config = [];
}
if (is_resource($contents)) {
return $this->driver->putStream($path, $contents, $config);
} else {
return $this->driver->put($path, $contents, $config);
}
}
示例6: push
/**
* {@inheritdoc}
*/
public function push(BackupInterface $backup)
{
$backupDirectory = $backup->getName();
if (!$this->flysystem->has($backupDirectory) && !$this->flysystem->createDir($backupDirectory)) {
throw new DestinationException(sprintf('Unable to create backup directory "%s" in flysystem destination.', $backupDirectory));
}
$removedBackupFiles = $this->getFiles($backupDirectory);
/**
* @var FileInterface $backupFile
*/
foreach ($backup->getFiles() as $backupFile) {
if (isset($removedBackupFiles[$backupFile->getRelativePath()])) {
unset($removedBackupFiles[$backupFile->getRelativePath()]);
}
$path = $backupDirectory . '/' . $backupFile->getRelativePath();
try {
if ($this->flysystem->has($path)) {
if ($backupFile->getModifiedAt() > new \DateTime('@' . $this->flysystem->getTimestamp($path))) {
$resource = fopen($backupFile->getPath(), 'r');
$this->flysystem->updateStream($path, $resource);
fclose($resource);
}
} else {
$resource = fopen($backupFile->getPath(), 'r');
$this->flysystem->putStream($path, $resource);
fclose($resource);
}
} catch (\Exception $e) {
throw new DestinationException(sprintf('Unable to backup file "%s" to flysystem destination.', $backupFile->getPath()), 0, $e);
}
}
/**
* @var FileInterface $removedBackupFile
*/
foreach ($removedBackupFiles as $removedBackupFile) {
$path = $backupDirectory . '/' . $removedBackupFile->getRelativePath();
try {
$this->flysystem->delete($path);
} catch (\Exception $e) {
throw new DestinationException(sprintf('Unable to cleanup backup destination "%s" after backup process, file "%s" could not be removed.', $backupDirectory, $path), 0, $e);
}
}
$this->removeEmptyDirectories($backupDirectory);
if (is_array($this->backups)) {
$this->backups[$backup->getName()] = $backup;
}
}
示例7: writeStream
/**
* @inheritdoc
*/
public function writeStream($path, $resource, $append = false)
{
$path = $this->strategy->encode($path);
if ($append === false && $this->filesystem->has($path)) {
$this->filesystem->delete($path);
}
$this->filesystem->putStream($path, $resource);
}
示例8: _save
/**
* Create new file and write into it from file pointer.
* Return new file path or false on error.
*
* @param resource $fp file pointer
* @param string $dir target dir path
* @param string $name file name
* @param array $stat file stat (required by some virtual fs)
* @return bool|string
**/
protected function _save($fp, $dir, $name, $stat)
{
$path = $this->_joinPath($dir, $name);
if ($this->fs->putStream($path, $fp)) {
return $path;
}
return false;
}
示例9: _save
/**
* Create new file and write into it from file pointer.
* Return new file path or false on error.
*
* @param resource $fp file pointer
* @param string $dir target dir path
* @param string $name file name
* @param array $stat file stat (required by some virtual fs)
* @return bool|string
**/
protected function _save($fp, $dir, $name, $stat)
{
$path = $this->_joinPath($dir, $name);
$ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
$config = [];
if (isset(self::$mimetypes[$ext])) {
$config['mimetype'] = self::$mimetypes[$ext];
}
return $this->_resultPath($this->fs->putStream($path, $fp, $config), $path);
return false;
}
示例10: putStream
/**
* Create a file or update if exists.
*
* @param string $path The path to the file.
* @param resource $resource The file handle.
* @param array $config An optional configuration array.
*
* @throws \League\Flysystem\InvalidArgumentException Thrown if $resource is not a resource.
*
* @return bool True on success, false on failure.
*/
public function putStream($path, $resource, array $config = [])
{
return $this->fileSystem->putStream($path, $resource, $config);
}