Php 如何控制文件';什么是打开和下载?

Php 如何控制文件';什么是打开和下载?,php,laravel,Php,Laravel,我正在使用Laravel 5.2。 如何控制文件的打开和下载? 像这样: xxx.php?filename=0001.jpg 有时浏览器会显示图像,有时会显示文件下载框?如何控制它?请阅读 例如: public function getFile() { $file = public_path(). "/path/to/file.jpg"; $headers = ['Content-Type' => 'image/jpeg']; // For download

我正在使用Laravel 5.2。
如何控制文件的打开和下载?
像这样:

xxx.php?filename=0001.jpg 
有时浏览器会显示图像,有时会显示文件下载框?如何控制它?

请阅读

例如:

public function getFile()
{
    $file = public_path(). "/path/to/file.jpg";
    $headers = ['Content-Type' => 'image/jpeg'];

    // For download
    return response()->download($file, 'someName.jpg', $headers);

    // For display
    return response()->file($file, $headers);
}

以下是我用来下载文件的功能:

public function download($file){
  $path = public_path('PATH/TO/YOUR/'. $file);
  header("Pragma: public");
  header("Content-type: ".mime_content_type($path));
  header("Content-length: " . filesize($path));
  header("Cache-Control: no-cache");
  header("Content-Transfer-Encoding: binary"); 
  header('Content-Disposition: attachement; filename="'.$file.'";');
  readfile($path);
}

这一切都取决于你实际上在做什么。一些代码/html可能是useful@RiggsFolly谢谢,有一些代码示例吗?@Sougata谢谢,有一些代码示例吗?