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); }
  1. 代码可能有点乱,请自己粘贴到编辑器


发表评论