moshaorui il y a 3 semaines
Parent
commit
215c3e5ab0
1 fichiers modifiés avec 15 ajouts et 7 suppressions
  1. 15 7
      app/Console/Commands/GeneratePreviewVideo.php

+ 15 - 7
app/Console/Commands/GeneratePreviewVideo.php

@@ -66,15 +66,13 @@ class GeneratePreviewVideo extends Command
 
         foreach ($reslut as $item) {
             try {
-                $video_url = $this->ossUrl($item->video_url);
-                $fileName = basename($video_url);
+                $video_oss_url = $this->ossUrl($item->video_url);
+                $fileName = basename($video_oss_url);
                 $fileInfo = pathinfo($fileName);
-                //下载$video_url到本地
-                $stream = $disk->readStream($video_url);
 
-                // 将流写入本地文件
-                file_put_contents($localPreviewPath, stream_get_contents($stream));
-                fclose($stream);
+                $localFilePath = $localPreviewPath. '/'. $fileName;
+                //下载$video_url到本地
+                $this->saveLocal($video_oss_url, $localFilePath);
 
                 exit;
 
@@ -107,6 +105,16 @@ class GeneratePreviewVideo extends Command
         return Command::SUCCESS;
     }
 
+    private  function saveLocal($url, $localPath) {
+        $remote = fopen($url, 'rb');
+        $local = fopen($localPath, 'wb');
+        while (!feof($remote)) {
+            fwrite($local, fread($remote, 8192)); // 8KB分块
+        }
+        fclose($remote);
+        fclose($local);
+    }
+
     private function ossUrl($url)
     {
         if (strpos($url, 'http:') === 0 || strpos($url, 'https:') === 0) {