mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-06 01:52:48 +08:00
fix(upload): 修复云存储上传失败时静默返回空save_name的问题
This commit is contained in:
@@ -19,6 +19,7 @@ use League\Flysystem\UnableToWriteFile;
|
||||
use RuntimeException;
|
||||
use think\Cache;
|
||||
use think\File;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* Class Driver
|
||||
@@ -104,10 +105,12 @@ abstract class Driver
|
||||
$stream = fopen($file->getRealPath(), 'r');
|
||||
$path = trim($path . '/' . $name, '/');
|
||||
|
||||
$result = $this->put($path, $stream, $options);
|
||||
|
||||
if (is_resource($stream)) {
|
||||
fclose($stream);
|
||||
try {
|
||||
$result = $this->put($path, $stream, $options);
|
||||
} finally {
|
||||
if (is_resource($stream)) {
|
||||
fclose($stream);
|
||||
}
|
||||
}
|
||||
|
||||
return $result ? $path : false;
|
||||
@@ -116,9 +119,12 @@ abstract class Driver
|
||||
protected function put(string $path, $contents, array $options = [])
|
||||
{
|
||||
try {
|
||||
$this->writeStream($path, $contents, $options);
|
||||
is_resource($contents)
|
||||
? $this->writeStream($path, $contents, $options)
|
||||
: $this->write($path, $contents, $options);
|
||||
} catch (UnableToWriteFile|UnableToSetVisibility $e) {
|
||||
return false;
|
||||
Log::error('Filesystem write failed: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user