相关疑难解决方法(0)

Laravel 5.3 Storage :: put创建一个带有文件名的目录

我正在使用Laravel的文件存储功能来保存文件:

public function dataPost(Request $request) {

    $fileInForm = 'doc';

    if ($request->hasFile($fileInForm)) {

        $file = $request->file($fileInForm);
        if ($file->isValid()) {

            // Filename is hashed filename + part of timestamp
            $hashedName = hash_file('md5', $file->path());
            $timestamp = microtime() * 1000000;

            $newFilename = $hashedName . $timestamp . '.' . $file->getClientOriginalExtension();

            Storage::disk('local')->put($newFilename, $file);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这样可以保存文件,但是在与文件名称相同的目录中,例如:

storage/app/952d6c009.jpg/952d6c009.jpg

要么

storage/app/234234234.jpg/234234234.jpg

这是预期的吗?有没有办法只为每个文件存储没有单独目录的文件?

谢谢!

php laravel laravel-5 laravel-filesystem laravel-5.3

17
推荐指数
3
解决办法
2万
查看次数