userId,FileEnum::SOURCE_USER); return $this->success('上传成功', ['url'=>env('project.project_url').'/'.$result['url']]); } catch (Exception $e) { return $this->fail($e->getMessage()); } } public function uploadVideoCover() { try { $deviceId = $this->request->param('device_id', ''); // Base64编码的图片字符串 $base64Image = $this->request->param('image'); // 这里只展示部分内容 // 去除前面的"data:"标识 $base64Data = substr($base64Image, strpos($base64Image, ',') + 1); // 将Base64编码的图片字符串转换为二进制数据 $binaryData = base64_decode($base64Data); // 创建图像对象 $imageObject = imagecreatefromstring($binaryData); $saveDir = 'uploads/images/' . date('Ymd'). '/'; if (!is_dir($saveDir)) { mkdir($saveDir, 0755, true); } $fileName = uniqid().'.png'; // 保存图片 imagepng($imageObject, $saveDir.$fileName); $file = File::create([ 'cid' => $deviceId, 'type' => FileEnum::IMAGE_TYPE, 'name' => $fileName, 'uri' => $saveDir . $fileName, 'source' => FileEnum::SOURCE_USER, 'source_id' => $this->userId, 'create_time' => time(), ]); return $this->success('上传成功', ['url'=>env('project.project_url').'/'.$saveDir.$fileName]); } catch (Exception $e) { return $this->fail($e->getMessage()); } } }