相关疑难解决方法(0)

Laravel 5:如何将本地文件复制到Amazon S3?

我正在Laravel 5中编写代码来定期备份MySQL数据库.到目前为止我的代码看起来像这样:

    $filename = 'database_backup_'.date('G_a_m_d_y').'.sql';
    $destination = storage_path() . '/backups/';

    $database = \Config::get('database.connections.mysql.database');
    $username = \Config::get('database.connections.mysql.username');
    $password = \Config::get('database.connections.mysql.password');

    $sql = "mysqldump $database --password=$password --user=$username --single-transaction >$destination" . $filename;

    $result = exec($sql, $output); // TODO: check $result

    // Copy database dump to S3

    $disk = \Storage::disk('s3');

    // ????????????????????????????????
    //  What goes here?
    // ????????????????????????????????
Run Code Online (Sandbox Code Playgroud)

我在网上看到的解决方案建议我做一些类似的事情:

$disk->put('my/bucket/' . $filename, file_get_contents($destination . $filename));
Run Code Online (Sandbox Code Playgroud)

但是,对于大文件,使用file_get_contents()不浪费吗?还有更好的解决方案吗?

upload amazon-s3 laravel laravel-5 laravel-filesystem

5
推荐指数
4
解决办法
8775
查看次数