加入收藏 | 设为首页 | 会员中心 | 我要投稿 汽车网 (https://www.0577qiche.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php后台添加文章时,直接下载远程图片

发布时间:2023-04-27 10:42:42 所属栏目:PHP教程 来源:
导读:<?PHP
auto_save_image($str);

function auto_save_image($body){

$img_array = explode(&#39;&&#39;,$body);

/*$img_array = array();

preg_match_all("/(src)=["|&#
<?PHP
    auto_save_image($str);

    function auto_save_image($body){

        $img_array = explode('&',$body);

        /*$img_array = array();

        preg_match_all("/(src)=["|'| ]{0,}(http://(.*).(gif|jpg|jpeg|bmp|png))["|'| ]{0,}/isU",$body,$img_array);

        $img_array = array_unique($img_array[2]);*/ //用于对img标签自动匹配

        set_time_limit(0);

        $imgPath = "uploads/allimg/".date("Ymd")."/";

        $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);

                if($get_file)

                        $fp = @fopen($rndFileName,"w");

                        @fwrite($fp,$get_file);

                        @fclose($fp);

                $body = @ereg_replace($value,$rndFileName,$body);

        return $body;

  

(编辑:汽车网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章