承接 utopia-php/storage 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

utopia-php/storage

Composer 安装命令:

composer require utopia-php/storage

包简介

A simple Storage library to manage application storage

README 文档

README

Important

This repository is a read-only mirror of the utopia-php monorepo. Development happens in packages/storage — please open issues and pull requests there.

Build Status Total Downloads Discord

Utopia Storage is a simple and lightweight library for managing application storage across multiple adapters. This library is designed to be easy to learn and use, with a consistent API regardless of the storage provider. This library is maintained by the Appwrite team.

This library is part of the Utopia Framework project.

Getting Started

Install using composer:

composer require utopia-php/storage

Basic Usage

<?php

require_once '../vendor/autoload.php';

use Utopia\Storage\Storage;
use Utopia\Storage\Device\Local;
use Utopia\Storage\Device\S3;
use Utopia\Storage\Device\DOSpaces;
use Utopia\Storage\Device\Backblaze;
use Utopia\Storage\Device\Linode;
use Utopia\Storage\Device\Wasabi;

// Set up a storage device (only need to choose one)
Storage::setDevice('files', new Local('/path/to/storage'));

// Common operations with any device
$device = Storage::getDevice('files');

// Upload a file
$device->upload('/local/path/to/file.png', 'destination/path/file.png');

// Check if file exists
$exists = $device->exists('destination/path/file.png');

// Read file contents
$contents = $device->read('destination/path/file.png');

// Delete a file
$device->delete('destination/path/file.png');

Available Adapters

Local Storage

Use the local filesystem for storing files.

use Utopia\Storage\Storage;
use Utopia\Storage\Device\Local;

// Initialize local storage
Storage::setDevice('files', new Local('/path/to/storage'));

AWS S3

Store files in Amazon S3 or compatible services.

use Utopia\Storage\Storage;
use Utopia\Storage\Device\S3;

// Initialize S3 storage
Storage::setDevice('files', new S3(
    'root', // Root path in bucket
    'YOUR_ACCESS_KEY',
    'YOUR_SECRET_KEY',
    'YOUR_BUCKET_NAME',
    S3::US_EAST_1, // Region (default: us-east-1)
    S3::ACL_PRIVATE // Access control (default: private)
));

// Available regions
// S3::US_EAST_1, S3::US_EAST_2, S3::US_WEST_1, S3::US_WEST_2, S3::AP_SOUTH_1, 
// S3::AP_NORTHEAST_1, S3::AP_NORTHEAST_2, S3::AP_NORTHEAST_3, S3::AP_SOUTHEAST_1,
// S3::AP_SOUTHEAST_2, S3::EU_CENTRAL_1, S3::EU_WEST_1, S3::EU_WEST_2, S3::EU_WEST_3,
// And more - check the S3 class for all available regions

// Available ACL options
// S3::ACL_PRIVATE, S3::ACL_PUBLIC_READ, S3::ACL_PUBLIC_READ_WRITE, S3::ACL_AUTHENTICATED_READ

DigitalOcean Spaces

Store files in DigitalOcean Spaces.

use Utopia\Storage\Storage;
use Utopia\Storage\Device\DOSpaces;

// Initialize DO Spaces storage
Storage::setDevice('files', new DOSpaces(
    'root', // Root path in bucket
    'YOUR_ACCESS_KEY',
    'YOUR_SECRET_KEY',
    'YOUR_BUCKET_NAME',
    DOSpaces::NYC3, // Region (default: nyc3)
    DOSpaces::ACL_PRIVATE // Access control (default: private)
));

// Available regions
// DOSpaces::NYC3, DOSpaces::SGP1, DOSpaces::FRA1, DOSpaces::SFO2, DOSpaces::SFO3, DOSpaces::AMS3

Backblaze B2

Store files in Backblaze B2 Cloud Storage.

use Utopia\Storage\Storage;
use Utopia\Storage\Device\Backblaze;

// Initialize Backblaze storage
Storage::setDevice('files', new Backblaze(
    'root', // Root path in bucket
    'YOUR_ACCESS_KEY',
    'YOUR_SECRET_KEY',
    'YOUR_BUCKET_NAME',
    Backblaze::US_WEST_004, // Region (default: us-west-004)
    Backblaze::ACL_PRIVATE // Access control (default: private)
));

// Available regions (clusters)
// Backblaze::US_WEST_000, Backblaze::US_WEST_001, Backblaze::US_WEST_002, 
// Backblaze::US_WEST_004, Backblaze::EU_CENTRAL_003

Linode Object Storage

Store files in Linode Object Storage.

use Utopia\Storage\Storage;
use Utopia\Storage\Device\Linode;

// Initialize Linode storage
Storage::setDevice('files', new Linode(
    'root', // Root path in bucket
    'YOUR_ACCESS_KEY',
    'YOUR_SECRET_KEY',
    'YOUR_BUCKET_NAME',
    Linode::EU_CENTRAL_1, // Region (default: eu-central-1)
    Linode::ACL_PRIVATE // Access control (default: private)
));

// Available regions
// Linode::EU_CENTRAL_1, Linode::US_SOUTHEAST_1, Linode::US_EAST_1, Linode::AP_SOUTH_1

Wasabi Cloud Storage

Store files in Wasabi Cloud Storage.

use Utopia\Storage\Storage;
use Utopia\Storage\Device\Wasabi;

// Initialize Wasabi storage
Storage::setDevice('files', new Wasabi(
    'root', // Root path in bucket
    'YOUR_ACCESS_KEY',
    'YOUR_SECRET_KEY',
    'YOUR_BUCKET_NAME',
    Wasabi::EU_CENTRAL_1, // Region (default: eu-central-1)
    Wasabi::ACL_PRIVATE // Access control (default: private)
));

// Available regions
// Wasabi::US_EAST_1, Wasabi::US_EAST_2, Wasabi::US_WEST_1, Wasabi::US_CENTRAL_1,
// Wasabi::EU_CENTRAL_1, Wasabi::EU_CENTRAL_2, Wasabi::EU_WEST_1, Wasabi::EU_WEST_2,
// Wasabi::AP_NORTHEAST_1, Wasabi::AP_NORTHEAST_2

Common Operations

All storage adapters provide a consistent API for working with files:

// Get storage device
$device = Storage::getDevice('files');

// Upload a file
$device->upload('/path/to/local/file.jpg', 'remote/path/file.jpg');

// Check if file exists
$exists = $device->exists('remote/path/file.jpg');

// Get file size
$size = $device->getFileSize('remote/path/file.jpg');

// Get file MIME type
$mime = $device->getFileMimeType('remote/path/file.jpg');

// Get file MD5 hash
$hash = $device->getFileHash('remote/path/file.jpg');

// Read file contents
$contents = $device->read('remote/path/file.jpg');

// Read partial file contents
$chunk = $device->read('remote/path/file.jpg', 0, 1024); // Read first 1KB

// Multipart/chunked uploads
$device->upload('/local/file.mp4', 'remote/video.mp4', 1, 3); // Part 1 of 3

// Create directory
$device->createDirectory('remote/new-directory');

// List files in directory
$files = $device->listFiles('remote/directory');

// Delete file
$device->delete('remote/path/file.jpg');

// Delete directory
$device->deleteDirectory('remote/directory');

// Transfer files between storage devices
$sourceDevice = Storage::getDevice('source');
$targetDevice = Storage::getDevice('target');

$sourceDevice->transfer('source/path.jpg', 'target/path.jpg', $targetDevice);

Adding New Adapters

For information on adding new storage adapters, see the Adding New Storage Adapter guide.

System Requirements

Utopia Storage requires PHP 7.4 or later. We recommend using the latest PHP version whenever possible.

Contributing

For security issues, please email security@appwrite.io instead of posting a public issue in GitHub.

All code contributions - including those of people having commit access - must go through a pull request and be approved by a core developer before being merged. This is to ensure a proper review of all the code.

We welcome you to contribute to the Utopia Storage library. For details on how to do this, please refer to our Contributing Guide.

License

This library is available under the MIT License.

Copyright

Copyright (c) 2019-2025 Appwrite Team <team@appwrite.io>

utopia-php/storage 适用场景与选型建议

utopia-php/storage 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 312.25k 次下载、GitHub Stars 达 31, 最近一次更新时间为 2021 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「php」 「storage」 「upf」 「utopia」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 utopia-php/storage 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 utopia-php/storage 我们能提供哪些服务?
定制开发 / 二次开发

基于 utopia-php/storage 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 312.25k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 31
  • 点击次数: 24
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 31
  • Watchers: 6
  • Forks: 58
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-22