public function autoSaveRemoteImage($str, $baseURI = '') { $str = stripslashes($str); $watermark = bpBase::loadSysCLass('watermark'); $img_array = array(); //$str = stripslashes($str); if (get_magic_quotes_gpc()) { $str = stripslashes($str); } preg_match_all('#src="(http://(((?!").)+).(jpg|gif|bmp|png))"#i', $str, $img_array); $img_array_urls = array_unique($img_array[1]); $dstFolder = ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'images'; @chmod($dstFolder, 0777); if ($baseURI) { $img_array_urls = $this->_expandlinks($img_array_urls, $baseURI); if ($img_array_urls) { exit; } } if ($img_array_urls) { $i = 0; $time = SYS_TIME; foreach ($img_array_urls as $k => $v) { if (!strpos($v, $_SERVER['HTTP_HOST'])) { //不保存本站的 $filenames = explode('.', $v); $filenamesCount = count($filenames); // $year = date('Y', $time); $month = date('m', $time); $pathInfo = upFileFolders($time); $dstFolder = $pathInfo['path']; $rand = randStr(4); $filePath = $dstFolder . $time . $rand . '.' . $filenames[$filenamesCount - 1]; // @httpCopy($v, $filePath, 5); //自动缩放 $imgInfo = @getimagesize($filePath); $maxPicWidth = intval(loadConfig('cmsContent', 'maxPicWidth')); $maxPicWidth = $maxPicWidth < 1 ? 500 : $maxPicWidth; if ($imgInfo[0] > $maxPicWidth) { $newWidth = $maxPicWidth; $newHeight = $imgInfo[1] * $newWidth / $imgInfo[0]; bpBase::loadSysClass('image'); image::zfResize($filePath, $filePath, $newWidth, $newHeight, 1, 2, 0, 0, 1); } // if (file_exists($filePath)) { $watermark->wm($filePath); $str = str_replace($v, 'http://' . $_SERVER['HTTP_HOST'] . CMS_DIR_PATH . $pathInfo['url'] . $time . $rand . '.' . $filenames[$filenamesCount - 1], $str); } } $i++; } } return $str; }