PHP code example of alphasnow / aliyun-oss-laravel
1. Go to this page and download the library: Download alphasnow/aliyun-oss-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alphasnow / aliyun-oss-laravel example snippets
"default" => env("FILESYSTEM_DRIVER", "oss"),
// ...
"disks"=>[
// ...
"oss" => [
"driver" => "oss",
"access_key_id" => env("OSS_ACCESS_KEY_ID"), // Required, yourAccessKeyId
"access_key_secret" => env("OSS_ACCESS_KEY_SECRET"), // Required, yourAccessKeySecret
"bucket" => env("OSS_BUCKET"), // Required, for example: my-bucket
"endpoint" => env("OSS_ENDPOINT"), // Required, for example: oss-cn-shanghai.aliyuncs.com
"internal" => env("OSS_INTERNAL", null), // Optional, for example: oss-cn-shanghai-internal.aliyuncs.com
"domain" => env("OSS_DOMAIN", null), // Optional, for example: oss.my-domain.com
"is_cname" => env("OSS_CNAME", false), // Optional, if the Endpoint is a custom domain name, this must be true, see: https://github.com/aliyun/aliyun-oss-php-sdk/blob/572d0f8e099e8630ae7139ed3fdedb926c7a760f/src/OSS/OssClient.php#L113C1-L122C78
"prefix" => env("OSS_PREFIX", ""), // Optional, the prefix of the store path
"use_ssl" => env("OSS_SSL", false), // Optional, whether to use HTTPS
"throw" => env("OSS_THROW", false), // Optional, whether to throw an exception that causes an error
"signatureVersion" => env("OSS_SIGNATURE_VERSION", "v1"), // Optional, select v1 or v4 as the signature version
"region" => env("OSS_REGION", ""), // Optional, for example: cn-shanghai, used only when v4 signature version is selected
"options" => [], // Optional, add global configuration parameters, For example: [\OSS\OssClient::OSS_CHECK_MD5 => false]
"macros" => [] // Optional, add custom Macro, For example: [\App\Macros\ListBuckets::class, \App\Macros\CreateBucket::class]
],
// ...
]
use Illuminate\Support\Facades\Storage;
$storage = Storage::disk("oss");
Storage::disk("oss")->appendObject("dir/path/news.txt", "The first line paragraph.", 0);
Storage::disk("oss")->appendObject("dir/path/news.txt", "The second line paragraph.", 25);
Storage::disk("oss")->appendObject("dir/path/news.txt", "The last line paragraph.", 51);
Storage::disk("oss")->appendFile("dir/path/file.zip", "dir/path/file.zip.001", 0);
Storage::disk("oss")->appendFile("dir/path/file.zip", "dir/path/file.zip.002", 1024);
Storage::disk("oss")->appendFile("dir/path/file.zip", "dir/path/file.zip.003", 1024);
Storage::disk("oss")->processObject("dir/path/image.jpg", "image/resize,l_1000");
namespace App\Macros;
use AlphaSnow\LaravelFilesystem\Aliyun\Macros\AliyunMacro;
class ListBuckets implements AliyunMacro
{
// ...
}
[
"macros" => [\App\Macros\ListBuckets::class]
]
Storage::disk("oss")->listBuckets()
use AlphaSnow\LaravelFilesystem\Aliyun\OssClientAdapter;
$adapter = new OssClientAdapter(Storage::disk("oss"));
$adapter->client()->appendObject($adapter->bucket(), $adapter->path("dir/path/file.txt"), "contents", 0, $adapter->options(["visibility" => "private"]));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.