27
04月
2015
private function downloadWeixinFile($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_NOBODY, 0); //只取body头 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $package = curl_exec($ch); $httpinfo = curl_getinfo($ch); curl_close($ch); $imageAll = array_merge(array('header' => $httpinfo), array('body' => $package)); return $imageAll; } private function saveWeixinFile($filename, $filecontent) { $local_file = fopen($filename, 'w'); if (false !== $local_file){ if (false !== fwrite($local_file, $filecontent)) { fclose($local_file); } } } public function uploadwximage(){ $url=$_POST["strurl"]; $fileInfo = $this->downloadWeixinFile($url); $dir = "/tpl/WShop/default/common/shopImages/" . Date("Ymd", time()) ; if(!is_dir($dir)){ mkdir($dir); } $filename=$dir."/".time().rand(10000,99999).".jpg"; $this->saveWeixinFile($filename, $fileInfo["body"]); $this->ajaxReturn($filename); }
- 代码可能有点乱,请自己粘贴到编辑器
特殊说明,本文版权归 ning个人博客 所有带原创标签请勿转载,转载请注明出处.
本文标题: 微信开发者下载图片(自己摸索的)