<?php
/**
 * Created by PhpStorm.
 * User: zhl
 * Date: 2023/9/14
 * Time: 15:42
 */
namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use ZipArchive;

class Demo extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'demo';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '测试案例';

    public function handle(){

        $filePath = public_path("www.lannx.net.zip");
        if(!file_exists($filePath)){
            $file = fopen($filePath, 'w');
            fclose($file);
        }

        $remoteFileUrl = 'https://sitefile.globalso.com/www.lannx.net.zip';
//        $remoteFileUrl = 'https://sitefile.globalso.com/www.fgl-logistics.com.zip';
        $localFilePath = public_path('abc.zip');

        $remoteFile = fopen($remoteFileUrl, 'rb');
        $localFile = fopen($localFilePath, 'wb');

        if ($remoteFile && $localFile) {
            while (!feof($remoteFile)) {
                fwrite($localFile, fread($remoteFile, 1024 * 8), 1024 * 8);
            }
            fclose($remoteFile);
            fclose($localFile);
            echo "File downloaded successfully";
        } else {
            echo "Failed to download file";
        }
        dd('end');
    }


}