【问题标题】:Downloading file from S3 using Flysystem in PHP在 PHP 中使用 Flysystem 从 S3 下载文件
【发布时间】:2023-03-29 03:06:02
【问题描述】:

我想知道是否可以得到一些帮助。

我在我的项目中使用 Flysystem 包。

目前,我正在使用以下代码将文件上传到 S3

$awss3 = new Flysystem(new AwsS3Adapter($client_details, 'bucket-name'));
$stream = fopen(public_path() . '/upload/' . $filename . '.gz', 'r+');
$awss3->writeStream($filename . '.gz', $stream);

这很完美。

但我不知道如何反向运行并下载文件。

任何帮助将不胜感激。

干杯,

【问题讨论】:

    标签: php laravel flysystem


    【解决方案1】:

    你可以使用flysystem readStream函数

    $stream = $filesystem->readStream('something/is/here.ext');
    

    那么你就可以直接使用写流直接写入磁盘了

    $filesystem->writeStream('backups/'.strftime('%G-%m-%d').'.backup', $stream)
    

    或者你可以直接使用下面的sn-p下载文件

                //Get File Extension
                $file_extension = ;
    
                //Get File Size
                $file_size = ;
    
                // Set the headers, prevent caching.
                header("Pragma: public");
                header("Expires: -1");
                header("Cache-Control: public, must-revalidate, post-check=0, pre-check=0");
    
                header("Content-Transfer-Encoding: binary");
                header("Content-Type:application/" . $file_extension);
                header('Content-Disposition: attachment; filename="' . $file_name . '"');
    
                header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    
                header('Content-Length: ' . $file_size);
                header('Accept-Ranges: bytes');
                fpassthru($stream);
    

    【讨论】:

      猜你喜欢
      • 2012-11-11
      • 1970-01-01
      • 2014-12-01
      • 2017-01-12
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多