我正在使用此代码将一些文件上传到laravel中的存储中:
$username=Auth::user()->name;
$patz=Storage::url("users/".$username."_".Auth::user()->id);
$now= new \Carbon\Carbon();
$fileName = 'ddt_'.$username."_".$now->getTimestamp().'.'.$request->ddt_file->getClientOriginalExtension();
$pathComplete=$request->ddt_file->storeAs($patz,$fileName);
$ddt_file_url= new Ddt_file_url(); //salvare ddt e poi prendere id
$ddt_file_url->fileUrl = $pathComplete;
$ddt_file_url->fileName = $fileName;
$ddt_file_url->company()->associate(Auth::user()->id);
$ddt_file_url->save();
该文件存在于文件夹中,但文件已损坏,当我尝试下载时,它不起作用。
这也是我用于下载的代码:
@if($ddtR->ddt_file_url_id)
<a href="{{asset(Storage::url($ddt_urls->where('id',$ddtR->ddt_file_url_id)->first()->fileUrl))}}" download="{{$ddt_urls->where('id',$ddtR->ddt_file_url_id)->first()->fileName}}">
<button type="button" class="btn btn-default">
Download ddt file <span class="fa icon-icona_download-01">
</span>
</button>
</a>
@else
<p>-</p>
@endif
我在dd()
和$patz
上分别跑了几笔$pathComplete
看起来都很正确!