2 回答

TA貢獻1852條經驗 獲得超1個贊
我通過正確添加必要的工廠、配置并注冊它們來修復它。
作曲家.json
{
"require": {
"illuminate/validation": "^6.16",
"illuminate/filesystem": "^6.16",
"illuminate/translation": "^6.16",
"illuminate/http": "^6.16",
"illuminate/config": "^6.16",
"jenssegers/blade": "^1.2",
"league/flysystem": "^1.0"
},
}
引導文件管理器:
use Illuminate\Container\Container;
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
use Illuminate\Http\Request;
use Illuminate\Filesystem\FilesystemManager;
use Illuminate\Config\Repository;
$instance = Container::getInstance();
$instance->bind('config', function () use ($instance) {
return new Repository([
'filesystems' => [
'default' => 'local',
'disks' => [
'local' =>[
'driver' => 'local',
'root' => '/absolut/path/to/upload/dir/,
]
]
]
]);
});
$instance->bind(FilesystemFactory::class, function () use ($instance) {
return new FilesystemManager($instance);
});
/** @var Request $request */
$request = new Request(
$_GET,
$_POST,
[],
$_COOKIE,
$_FILES,
$_SERVER
);

TA貢獻1825條經驗 獲得超4個贊
當使用獨立組件并希望使用文件系統(tǒng)Illuminate\Filesystem\Filesystem::move()時,可能是使用方法或其他方法將文件保存在磁盤上的最簡單方法。Illuminate\Http\Request請看下面的代碼:
<?php
use Illuminate\Http\Request;
use Illuminate\Filesystem\Filesystem;
// Bootstraps request object
$request = new Request(
$_GET,
$_POST,
[],
$_COOKIE,
$_FILES,
$_SERVER
);
// Illuminate\Http\UploadedFile is available on $request->image
$path = $request->image->path();
$extension = $request->image->extension();
// Don't use destination thus. It's for demonstration purpose only
// Make sure upload directory is writable
$destination = 'uploads/' . mt_rand() . '.' . $extension;
// Here is the moment
$file = new Filesystem();
$file->move($path, $destination);
- 2 回答
- 0 關注
- 133 瀏覽
添加回答
舉報