吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3135|回复: 1
收起左侧

[其他转载] php版本下载页面图片支持微信里的,有时候不想一直右键

[复制链接]
zhan170 发表于 2015-4-11 16:14
本帖最后由 zhan170 于 2015-4-11 16:20 编辑

[PHP] 纯文本查看 复制代码
<!DOCTYPE html>
<html>
<head>
        <meta charset="utf-8">
        <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
        <meta name="viewport" content="width=device-width" />
        <title>标题</title>
</head>
<body>
<?php
set_time_limit(0);
function get_basename($filename){  
        return preg_replace('/^.+[\\\\\\/]/', '', $filename);  
}   
function https_request($url, $data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}        
function xzimg($pic,$houzhui){
        $filetime = time(); //得到时间戳
        $filepath = "img/";//图片保存的路径目录 
        if(!is_dir($filepath)){
            mkdir($filepath,0777, true);
        }
                $xx=strtolower($pic);                
                if($houzhui==''){
                        if(strstr($xx,".jpg")){
                                $houzhui="jpg";
                        }
                        if(strstr($xx,".png")){
                                $houzhui="png";
                        }
                        if(strstr($xx,".gif")){
                                $houzhui="gif";
                        }
                        if(strstr($xx,".bmp")){
                                $houzhui="bmp";
                        }
                        if(strstr($xx,".jpeg")){
                                $houzhui="jpeg";
                        }
                }
                if(strstr($xx,"mmbiz.qpic.cn")){
                        $filename = date("YmdHis",$filetime).rand(100,999).'.'.$houzhui;
                }else{
                        $dd=get_basename($pic);
                        $cc=parse_url($pic);
                        $dd=str_replace($cc["query"],"",$dd);
                        $dd=str_replace("?","",$dd);
                        $filename = $dd;
                }
        $newfname = $filepath.$filename;
                   $data = file_get_contents($pic);
        $fp = fopen($newfname,"w");      
        fwrite($fp, $data); 
        fclose($fp);                
                if (file_exists($newfname)) {
                        echo $filename.'<br>';
                }
}
function imgall($url){
        $str = https_request($url);
        $list = array();    //这里存放结果map  
        $c1 = preg_match_all('/<img\s.*?>/', $str, $m1);  //先取出所有img标签文本  
        //print_r($m1);
        for($i=0; $i<$c1; $i++) {    //对所有的img标签进行取属性  
                $c2 = preg_match_all('/(\w+)\s*=\s*(?:(?:(["\'])(.*?)(?=\2))|([^\/\s]*))/', $m1[0][$i], $m2);   //匹配出所有的属性  
                for($j=0; $j<$c2; $j++) {    //将匹配完的结果进行结构重组  
                        $list[$i][$m2[1][$j]] = !empty($m2[4][$j]) ? $m2[4][$j] : $m2[3][$j];  
                }  
        }        
        for($k=0;$k<count($list);$k++){
                $src=$list[$k]["src"];
                if(strstr($src,"mmbiz.qpic.cn")){
                        $size = getimagesize($src);
                        $fp = fopen($src, "rb");
                        if ($size && $fp) {                                
                                if(strstr($size['mime'],".png")){
                                        $houzhui="png";
                                }elseif(strstr($size['mime'],".gif")){
                                        $houzhui="gif";
                                }else{
                                        $houzhui="jpg";
                                }
                                xzimg($src,$houzhui);
                        }
                }else{
                        $houzhui=get_extension($src);
                        if($houzhui!=''){
                                xzimg($src,$houzhui);
                        }                        
                }                
        }
}
function get_extension($file)
{
        return pathinfo($file, PATHINFO_EXTENSION);
}
$lianjie=trim($_POST["wd"]);
?>
<form action="?" method="post">
        <input value="" name="wd" style="width: 400px; height: 20px;">
        <input type="submit" value="go" style="padding:4px 10px;font-size:16px;">
</form>
<?php
if($lianjie!=''){
        imgall($lianjie);
        echo $lianjie;
}
?>

111.jpg

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

htcperfect 发表于 2015-4-11 16:57
这个php就是利用正则获取网页图片的,的确很方便
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-9-22 19:32

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表