Laravel使用SFTP上传文件
生活随笔
收集整理的這篇文章主要介紹了
Laravel使用SFTP上传文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先使用composer安裝第三方包
composer require graham-campbell/flysystem #生產配置文件 php artisan vendor:publish這個第三方包的github地址為:https://github.com/GrahamCampbell/Laravel-Flysystem
使用Demo
<?phpnamespace 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);}} }總結
以上是生活随笔為你收集整理的Laravel使用SFTP上传文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JVM原理(二)执行引擎篇(JVM程序执
- 下一篇: 核心网学习1