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个赞
当使用独立组件并希望使用文件系统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 关注
- 91 浏览
添加回答
举报