Laravel 5 - 文件下载失败的问题
问题描述:
I'm new to Laravel 5.4 and I need to download few PDF files from its database. There's an issue downloading the files.
Here is my controller.
public function download_files(){
$dowaloads=DB::table('dowanloadable_files')->get();
return view('dowanload.dowanload', compact('dowaloads'));
}
Here is my view.
<tbody>
@foreach($dowaloads as $download)
<tr>
<td>{{ $download->file_title }}</td>
<td><a href="download/{{ $download->file_name }}" download="{{ $download->file_name }}"> <button type="button" class="btn btn-primary">Dowanload</button></a></td>
</tr>
@endforeach
i place all these PDF files in public/download directory as well but this problem not changed. Is this due to no files in the database?
我是Laravel 5.4的新手,我需要从其数据库中下载一些PDF文件。 下载文件时出现问题。 p>
这是我的控制器。 p>
public function download_files(){
$ dowaloads = DB :: table('dowanloadable_files') - &gt; get();
返回视图('dowanload.dowanload',compact( 'dowaloads'));
}
code> pre>
这是我的观点。 p>
&lt; tbody&gt;
@foreach($ dowaloads as $ download)
&lt; tr&gt;
&lt; td&gt; {{$ download-&gt; file_title}}&lt; / td&gt;
&lt; td&gt;&lt; a href =“ 下载/ {{$ download-&gt; file_name}}“download =”{{$ download-&gt; file_name}}“&gt; &lt; button type =“button”class =“btn btn-primary”&gt; Dowanload&lt; / button&gt;&lt; / a&gt;&lt; / td&gt;
&lt; / tr&gt;
@endforeach
code> pre>
p>
我将所有这些PDF文件也放在公共/下载目录中,但这个问题没有改变。 这是由于数据库中没有文件吗? p>
答
You are using wrong folder name use like this, seen in your download folder image.
<td><a href="/dowanload/{{ $download->file_name }}" download="/dowanload/{{ $download->file_name }}"> <button type="button" class="btn btn-primary">Dowanload</button></a></td>