content); if (isset($content['url'])) { $filePath = public_path($content['url']); $array = $this->toArray(); $array['content'] = file_get_contents($filePath) ?: ''; if ($array['content']) { $replace = Base::fillUrl('uploads'); $array['content'] = str_replace('{{RemoteURL}}uploads', $replace, $array['content']); } return $array; } return $this->toArray(); } /** * 保存任务详情至文件并返回文件路径 * @param $task_id * @param $content * @return string */ public static function saveContent($task_id, $content) { @ini_set("pcre.backtrack_limit", 999999999); // $oldContent = $content; $path = 'uploads/task/content/' . date("Ym") . '/' . $task_id . '/'; // preg_match_all('/]*?src=\\\\?["\']data:image\/(png|jpg|jpeg|webp);base64,(.*?)\\\\?["\']/s', $content, $matchs); foreach ($matchs[2] as $key => $text) { $tmpPath = $path . 'attached/'; Base::makeDir(public_path($tmpPath)); $tmpPath .= md5($text) . "." . $matchs[1][$key]; if (Base::saveContentImage(public_path($tmpPath), base64_decode($text))) { $paramet = getimagesize(public_path($tmpPath)); $content = str_replace($matchs[0][$key], ']*?src=\\\\?["\'])(https?:\/\/[^\/]+\/)(uploads\/[^\s"\'>]+)(\\\\?["\'][^>]*?>)/i', $content, $matches); foreach ($matches[0] as $key => $fullMatch) { $filePath = public_path($matches[3][$key]); if (file_exists($filePath)) { $replacement = $matches[1][$key] . '{{RemoteURL}}' . $matches[3][$key] . $matches[4][$key]; $content = str_replace($fullMatch, $replacement, $content); } } // $filePath = $path . md5($content); $publicPath = public_path($filePath); Base::makeDir(dirname($publicPath)); $result = file_put_contents($publicPath, $content); if(!$result && $oldContent){ throw new ApiException("保存任务详情至文件失败,请重试"); } // return $filePath; } }