lh 2 miesięcy temu
rodzic
commit
3c3a3d5c7f
1 zmienionych plików z 20 dodań i 2 usunięć
  1. 20 2
      app/Libs/Helpers.php

+ 20 - 2
app/Libs/Helpers.php

@@ -995,7 +995,9 @@ function compressVideo($videoUrl, $prefix = 'videos')
         // 创建临时目录
         // 创建临时目录
         $tempDir = storage_path('app/temp/videos');
         $tempDir = storage_path('app/temp/videos');
         if (!is_dir($tempDir)) {
         if (!is_dir($tempDir)) {
-            mkdir($tempDir, 0755, true);
+            mkdir($tempDir, 0775, true);
+            // 确保目录权限正确
+            chmod($tempDir, 0775);
         }
         }
 
 
         // 生成唯一文件名
         // 生成唯一文件名
@@ -1008,7 +1010,20 @@ function compressVideo($videoUrl, $prefix = 'videos')
         dLog('video_compress')->info('开始下载视频', ['url' => $videoUrl]);
         dLog('video_compress')->info('开始下载视频', ['url' => $videoUrl]);
         $client = new \GuzzleHttp\Client(['timeout' => 300]);
         $client = new \GuzzleHttp\Client(['timeout' => 300]);
         $response = $client->get($videoUrl);
         $response = $client->get($videoUrl);
-        file_put_contents($inputFile, $response->getBody()->getContents());
+        
+        // 使用更安全的方式写入文件
+        $fileContent = $response->getBody()->getContents();
+        if (file_put_contents($inputFile, $fileContent) === false) {
+            dLog('video_compress')->error('视频文件写入失败', [
+                'url' => $videoUrl,
+                'file' => $inputFile,
+                'dir_writable' => is_writable($tempDir)
+            ]);
+            return '';
+        }
+        
+        // 设置文件权限
+        chmod($inputFile, 0664);
 
 
         if (!file_exists($inputFile)) {
         if (!file_exists($inputFile)) {
             dLog('video_compress')->error('视频下载失败', ['url' => $videoUrl]);
             dLog('video_compress')->error('视频下载失败', ['url' => $videoUrl]);
@@ -1073,6 +1088,9 @@ function compressVideo($videoUrl, $prefix = 'videos')
             @unlink($inputFile);
             @unlink($inputFile);
             return '';
             return '';
         }
         }
+        
+        // 设置输出文件权限
+        chmod($outputFile, 0664);
 
 
         $outputFileSize = filesize($outputFile);
         $outputFileSize = filesize($outputFile);
         $compressionRatio = round((1 - $outputFileSize / $inputFileSize) * 100, 2);
         $compressionRatio = round((1 - $outputFileSize / $inputFileSize) * 100, 2);