如何为 laravel 本地存储生成临时文件下载 url?

How to generate temporary file download url for laravel local storage?

来自Laravel官方文档:

For files stored using the s3 or rackspace driver, you may create a temporary URL to a given file using the temporaryUrl method.

有什么方法可以临时下载 url 文件而不是使用 s3/etc 并且仅 本地存储 。我正在使用 https://github.com/spatie/laravel-medialibrary 库进行开发。

public function downloadFileAction()
{
    if (isset($_REQUEST['file_name'])) {
        $pathFile = STORAGE_PATH.'/'.$_REQUEST['file_name'];

        header('Content-Description: File Transfer');
        header('Content-Disposition: attachment; filename="'.$_REQUEST['file_name'].'"');
        header('Content-Type: application/octet-stream');
        header('Content-Transfer-Encoding: binary');
        header('Content-Length: ' . filesize($pathFile));
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Expires: 0');
        readfile($pathFile);
    }
}




public function uploadFile(array $file)
    {
        $storagePath = STORAGE_PATH;

        @mkdir($storagePath, 0777, true);

        $fullPath = $storagePath. uniqid (time()). $file['name'];
        $fileTemp = $file['tmp_name'];

        move_uploaded_file($fileTemp, $fullPath);

        return $fullPath;
    }

在你的控制器中,你可以用这个获取文件:$_FILES