我正在使用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
这是预期的吗?有没有办法只为每个文件存储没有单独目录的文件?
谢谢!