/** * 新闻内部图片上传到ftp */ public function insertInfoImg( $content ) { $str = $content; preg_match_all('/<img.*?src="(.*?)".*?>/is',$content,$array); $path = \Config::get('app.imagePath'); foreach( $array[1] as $v) { $img = strstr($v,$path,true); if(is_bool($img)) { $basePtah = public_path().$v; $fileTo = substr($basePtah, strrpos($basePtah, '/')+1); $obj = new \FtpAbstract(); $obj->uploadNewsImg($basePtah,$fileTo); //参数1.文件的本地路径 2.文件名称 $str = str_replace($v, $path.'/news/'.$fileTo, $str); //替换内容的img的src } } return $str; }