作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into master-lyh-edit

<?php
/**
* @remark :
* @name :ProductFileUpload.php
* @author :lyh
* @method :post
* @time :2024/6/18 15:43
*/
namespace App\Console\Commands\Test;
use App\Models\File\File;
use App\Models\Product\Product;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ProductFileUpload extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'files_upload {project_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = '重新上传文件获取文件后缀';
/**
* @remark :
* @name :handle
* @author :lyh
* @method :post
* @time :2024/6/18 15:46
*/
public function handle(){
$project_id = $this->argument('project_id');
ProjectServer::useProject($project_id);
$productModel = new Product();
$lists = $productModel->list(['status'=>1,'id'=>['<=',106]]);
foreach ($lists as $k => $v){
if(!empty($v['files']) && !empty($v['files']['url'])){
$url = str_replace_url($v['files']['url']);
//获取当前图片的原名称
$files = new File();
$fileInfo = $files->read(['path'=>$url,'project_id'=>$project_id]);
if($fileInfo === false){
continue;
}
$newName = $fileInfo['name'];
$code = $this->synchronizationFile($url,$newName);
if((int)$code == 200){
echo date('Y-m-d H:i:s') . '编辑的path为:'. $url .',主键id:'. $v['id'] . PHP_EOL;
$v['files']['url'] = $newName;
$productModel->edit(['files'=>json_encode($v['files'])],['id'=>$v['id']]);
}
}
}
DB::disconnect('custom_mysql');
}
/**
* @remark :指定同步文件到獨立177服務器
* @name :synchronizationFile
* @author :lyh
* @method :post
* @time :2024/4/8 11:10
*/
public function synchronizationFile($path_name,$newName){
//同步到大文件
$file_path = config('filesystems.disks.cos')['cdn1'].$path_name;
echo date('Y-m-d H:i:s') . '编辑的path为:'. $file_path. PHP_EOL;
$directoryPath = pathinfo($path_name, PATHINFO_DIRNAME);
$cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" -F "file_name='.$newName.'" https://v6-file.globalso.com/fileUploads.php';
return shell_exec($cmd);
}
}
... ...
... ... @@ -343,11 +343,11 @@ class FileController
$this->response('指定文件不存在!', Code::USER_ERROR);
}
$fileUrl = getFileUrl($info['path'],$info['is_cos']);
// $fileName = basename($fileUrl); // 要保存的文件名
// 设置响应头
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . !empty($info['name']) ? $info['name'] : '未命名'.basename($info['path']) . '"');
$name = !empty($info['name']) ? $info['name'] : '未命名'.basename($info['path']);
header('Content-Disposition: attachment; filename="'.$name.'"');
// 下载文件
readfile($fileUrl);
}
... ...