初始上传

This commit is contained in:
2026-04-04 17:27:12 +08:00
parent 4d80d28eb4
commit b7e11774ee
11191 changed files with 1588469 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?php
/**
* 指定上传文件的Content-Type
* 此设置可以不指定文件路径后缀
*/
use League\Flysystem\Filesystem;
use Xxtime\Flysystem\Aliyun\OssAdapter;
use finfo;
class uploadWithContentType
{
public function demo()
{
$fileContent = file_get_contents('/path/to/file.jpg');
// 配置
$adapter = new OssAdapter([
'accessId' => "xxx",
'accessSecret' => "xxx",
'bucket' => "xxx",
'endpoint' => "xxx",
'timeout' => 3600,
'connectTimeout' => 10,
]);
$filesystem = new Filesystem($adapter);
// 设置属性
// 如设置了Content-Type则可以不指定路径的后缀 (即$filePath可以不包含.jpg等后缀名)
$fInfo = new finfo(FILEINFO_MIME_TYPE);
$mimeType = $fInfo->buffer($fileContent);
$config = [
"Content-Type" => $mimeType
];
$filePath = "uploadPathTest/" . time();
// 上传
if (!$filesystem->write($filePath, $fileContent, $config)) {
exit("failed to upload");
}
// 获取信息
$raw = $adapter->supports->getFlashData();
var_dump($raw);
}
}