<?php
function GrabImage($url,$filename="") {
  if($url==""):return false;endif;

  if($filename=="") {
    $ext=strrchr($url,".");
    if($ext!=".gif" && $ext!=".jpg"):return false;endif;
    $filename=date("dMYHis").$ext;
  }

  ob_start();
  readfile($url);
  $img = ob_get_contents();
  ob_end_clean();
  $size = strlen($img);

  $fp2=@fopen($filename, "a");
  fwrite($fp2,$img);
  fclose($fp2);

  return $filename;
}


$img=GrabImage("http://news.bbc.co.uk/images/_1978837_detector_ap100.jpg","");
if($img):echo '<pre><img src="/UploadFiles/2021-04-02/'.$img.'">
 


?>

dedecms中的:

       if(!empty($saveremoteimg))
        {
                $body = stripslashes($body);
                $img_array = array();
                preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\/\/(.*)\.(gif|jpg|jpeg|bmp|png))/isU",$body,$img_array);
                $img_array = array_unique($img_array[2]);
                set_time_limit(0);
                $imgUrl = $img_dir."/".strftime("%Y%m%d",time());
                $imgPath = $base_dir.$imgUrl;
                $milliSecond = strftime("%H%M%S",time());
                if(!is_dir($imgPath)) @mkdir($imgPath,0777);
                foreach($img_array as $key =>$value)
                {
                        $value = trim($value);
                        $get_file = @file_get_contents($value);
                        $rndFileName = $imgPath."/".$milliSecond.$key.".".substr($value,-3,3);
                        $fileurl = $imgUrl."/".$milliSecond.$key.".".substr($value,-3,3);
                        if($get_file)
                        {
                                $fp = @fopen($rndFileName,"w");
                                @fwrite($fp,$get_file);
                                @fclose($fp);
                        }
                        $body = ereg_replace($value,$fileurl,$body);
                }
                $body = addslashes($body);
        }
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!