{"id":426,"date":"2021-07-22T18:34:07","date_gmt":"2021-07-22T10:34:07","guid":{"rendered":"https:\/\/wp.dj47.top\/?p=426"},"modified":"2022-04-16T14:48:33","modified_gmt":"2022-04-16T06:48:33","slug":"curl%e4%b8%8b%e8%bd%bd%e8%bf%9c%e7%a8%8b%e5%9b%be%e7%89%87%e7%a4%ba%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.djlog.cn\/?p=426","title":{"rendered":"CURL\u4e0b\u8f7d\u8fdc\u7a0b\u56fe\u7247\u793a\u4f8b"},"content":{"rendered":"<pre class=\"language-php\"><code>&lt;?php\r\nnamespace app\\index\\controller;\r\n \r\nclass Temp\r\n{\r\n    \/\/\u4e0b\u8f7d\u5b66\u6821logo\r\n    public function getImg(){\r\n        $img_path = 'https:\/\/static-data.eol.cn\/upload\/logo\/102.jpg';\r\n        $this-&gt;downloadImage($img_path);\r\n    }\r\n     \r\n    public function downloadImage($url, $path='.\/images\/')\r\n    {\r\n        \/\/\u6a21\u62df\u8bf7\u6c42\u6e90IP\u5730\u5740\u3010\u6682\u7528\u767e\u5ea6\u5730\u5740\u6bb5\u3011\r\n        $cip = '123.125.68.'.mt_rand(0,254);\r\n        $xip = '125.90.88.'.mt_rand(0,254);\r\n        $header = array(\r\n            'CLIENT-IP:'.$cip,\r\n            'X-FORWARDED-FOR:'.$xip,\r\n        );\r\n \r\n        $ch = curl_init();\r\n        curl_setopt($ch, CURLOPT_URL, $url);\r\n        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\r\n        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);\r\n        curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);\r\n        curl_setopt($ch, CURLOPT_REFERER, \"http:\/\/www.baidu.com\/\");\r\n        $file = curl_exec($ch);\r\n        curl_close($ch);\r\n \r\n        $this-&gt;saveAsImage($url, $file, $path);\r\n    }\r\n \r\n    public function saveAsImage($url, $file, $path)\r\n    {\r\n        $filename = pathinfo($url, PATHINFO_BASENAME);\r\n        $resource = fopen($path . $filename, 'w+');\r\n        fwrite($resource, $file);\r\n        fclose($resource);\r\n    }\r\n \r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&lt;?php namespace app\\index\\controller; class Temp { \/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"class_list":["post-426","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts\/426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=426"}],"version-history":[{"count":0,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts\/426\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}