private function postImageToLocal(\App\Model\Post $post) { $sum_count = 0; $abs_count = 0; $err_count = 0; $rel_count = 0; $suc_count = 0; $post->content = preg_replace_callback("/<img.*?src=\"(.+?)\".*?>/ism", function ($data) use($post, &$sum_count, &$abs_count, &$err_count, &$rel_count, &$suc_count) { $sum_count++; if (preg_match('/^http:|https:|\\/\\//i', $data[1])) { $abs_count++; $path = tempnam('/tmp', 'sex'); $file_content = @file_get_contents($data[1]); if (!$file_content) { $err_count++; return '#'; } else { $suc_count++; } file_put_contents($path, $file_content); $file = new \Symfony\Component\HttpFoundation\File\UploadedFile($path, $data[1], null, null, null, true); $model = \App\Model\File::create(['type' => 'post_image', 'name' => $post->id, 'file' => $file]); $model = \App\Model\File::find($model->id); return str_replace($data[1], $model->getFileUrl(), $data[0]); } else { $rel_count++; } return $data[0]; }, $post->content); if ($suc_count > 0) { $post->save(); } $this->info('总数:' . $sum_count); $this->info('绝对:' . $abs_count); $this->info('失败:' . $err_count); $this->info('相对:' . $rel_count); $this->info('成功:' . $suc_count); }
public function delete($id) { File::find($id)->delete(); return redirect("/dream/file")->with('message', '信息删除成功!'); }