demo.php
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?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');
    }
}