| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- use Illuminate\Database\Migrations\Migration;
- use Illuminate\Filesystem\Filesystem;
- class RunDownloadFile extends Migration
- {
- /**
- * Run the migrations.
- *
- * @return void
- */
- public function up()
- {
- $filesystem = app(Filesystem::class);
- //下载
- $url = 'https://downloads.yunzmall.com/company_backend/business_font.zip';
- $path = base_path('business/business_font.zip');
- if (file_exists(base_path('business/business_font'))) {
- return;
- }
- if (!file_exists($path)) {
- try {
- Utils::download($url, $path);
- \Log::debug('----business zip 下载ok----');
- } catch (\Exception $e) {
- \Log::debug('----business zip 下载失败----');
- return;
- }
- }
- //删除本地文件
- if (file_exists($path)) {
- $filesystem->deleteDirectory(base_path('business/business_font'));
- \Log::debug('----business dir delete----');
- }
- //解压
- if (file_exists($path)) {
- $zip = new \ZipArchive();
- $res = $zip->open($path);
- if ($res === true) {
- try {
- $zip->extractTo(base_path('business'));
- } catch (\Exception $e) {
- $zip->close();
- \Log::debug('----business zip 解压失败----');
- return false;
- }
- } else {
- $zip->close();
- \Log::debug('----business zip 解压下载失败----');
- return false;
- }
- $zip->close();
- \Log::debug('----business zip 解压ok----');
- }
- //删除压缩文件
- if (file_exists($path)) {
- @unlink($path);
- \Log::debug('----business zip 删除ok----');
- }
- }
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- //
- }
- }
|