Laravel 5: How do you copy a local file to Amazon S3?

后端 未结 6 2101
心在旅途
心在旅途 2021-02-08 11:53

I\'m writing code in Laravel 5 to periodically backup a MySQL database. My code thus far looks like this:

    $filename = \'database_backup_\'.date(\'G_a_m_d_y\         


        
6条回答
  •  日久生厌
    2021-02-08 12:42

    There is a way to copy files without needing to load the file contents into memory.

    You will also need to import the following:

    use League\Flysystem\MountManager;
    

    Now you can copy the file like so:

    $mountManager = new MountManager([
        's3' => \Storage::disk('s3')->getDriver(),
        'local' => \Storage::disk('local')->getDriver(),
    ]);
    $mountManager->copy('s3://path/to/file.txt', 'local://path/to/output/file.txt');
    

提交回复
热议问题