DownPic.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/11/24
  6. * Time: 上午11:48
  7. */
  8. namespace App\Console\Commands;
  9. use Log;
  10. use App\Modules\Finance\Models\Bill;
  11. use GuzzleHttp;
  12. use Illuminate\Console\Command;
  13. use Storage;
  14. class DownPic extends Command
  15. {
  16. /**
  17. * 执行命令 php artisan bill_task
  18. *
  19. * The name and signature of the console command.
  20. *
  21. * @var string
  22. */
  23. protected $signature = 'down_pic';
  24. /**
  25. * The console command description.
  26. *
  27. * @var string
  28. */
  29. protected $description = '下载图片';
  30. public function handle() {
  31. $client = new GuzzleHttp\Client();
  32. $fp = fopen(storage_path("app/abc.txt"), 'r');
  33. $str = fread($fp,filesize(storage_path("app/abc.txt")));
  34. $arraylist= explode("\n",$str);
  35. for($i=0;$i<count($arraylist);$i++) //把它们全部输出来
  36. {
  37. if(!empty($arraylist[$i])) {
  38. echo $arraylist[$i]." \n";
  39. $data = $client->request('GET', $arraylist[$i])->getBody()->getContents();
  40. $filename = str_replace("http://cdn-novel.weituibao.com/", "", $arraylist[$i]);
  41. echo $filename." \n";
  42. Storage::disk('local')->put($filename, $data);
  43. }
  44. }
  45. }
  46. }