Laravel使用SFTP上传文件

首先使用composer安装第三方包

composer require graham-campbell/flysystem
#生产配置文件
php artisan vendor:publish

这个第三方包的github地址为:https://github.com/GrahamCampbell/Laravel-Flysystem

使用Demo

<?php

namespace App\Console\Commands;

use App\Member;
use GrahamCampbell\Flysystem\Facades\Flysystem;
use Http;
use Log;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;

class SynchWechatRegisterUsersToArvato extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'SynchWechatRegisterUsersToArvato {dateday?}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '同步注册会员到arvato';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        ini_set('memory_limit', '1024M');
        set_time_limit(3600);

        $this->createdir(storage_path('userregister'));
        if($dateday = $this->argument('dateday')){
            $start = date('Y-m-d 00:00:00',strtotime($dateday));
            $end = date('Y-m-d 00:00:00',strtotime("$dateday + 1 day"));
            $filename = 'register_users_'.date('Ymd',strtotime($dateday)).'.csv';
            $filepath = storage_path('userregister/'.$filename);
        }else{
            $start = date('Y-m-d 00:00:00',strtotime('-1 day'));
            $end = date('Y-m-d 00:00:00');
            $filename = 'register_users_'.date('Ymd',strtotime('- 1day')).'.csv';
            $filepath = storage_path('userregister/'.$filename);
        }
		$header = [];
		$memberList = [];
        file_put_contents($filepath,$header."\n");
        file_put_contents($filepath,$memberList,FILE_APPEND);
        if(Flysystem::put('/In/register_user/'.$filename,file_get_contents($filepath))){
            echo '上传成功';
        }else{
            Log::info('register_user_updaload'.$filename.'上传失败');
            echo '上传失败';
        }

    }

    public function createdir($path){
        if(!file_exists($path)){
            mkdir($path,0777);
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值