强制使用laravel下载文件的链接

the link

I want to be able to click on a link and it downloads a file from Laravel public folder. I need to see the routes and controller that I need to write to achieve this.

Could I achieve this via php only?

if (isset($_GET["download"])){

    $search = $_GET["download"];
    $dir =  $clipDir->clip_path1($search); 
    $Base = basename($dir);

    if (file_exists($dir)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.$Base);
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($dir));
    ob_clean();
    flush();
    readfile($dir);
    exit;
    }  else {
    echo 'File Dont Exit <br />'.  print_r($dir);
    return false;

}

Files are stored in Laravels public folder .

Take a look at Response::download and do something like:

return Response::download($yourfile, 'nameoffile.extension');

You can use anchor tag directly to download the file inside blade template like this

<a href="{{ URL::to( '/uploads/' . $filename)  }}" target="_blank">{{ $filename }}</a>

Works for me on Laravel 5.4 also.