微信上傳媒體檔案 報41005 解決方案 php的巨坑
阿新 • • 發佈:2019-01-28
此問題是因為php新版本更新,對函式的支援有改變導致的
解決如下
$postMedia = array(); $postMedia['access_token'] = $json->access_token; $postMedia['type'] = 'image'; foreach ($imgs as $img) { file_put_contents(CONF_PATH . 'img_' . $img['id'] . '.jpg', file_get_contents($img['pic'])); //$postMedia['media']=$_SERVER['DOCUMENT_ROOT'].str_replace('http://'.$_SERVER['HTTP_HOST'],'',$img['pic']); //$postMedia['media']=$_SERVER['DOCUMENT_ROOT'].str_replace('./','/',CONF_PATH.'img_'.$img['id'].'.jpg'); // @只支援 5.5以下版本 //$postMedia['media']=CONF_PATH.'img_'.$img['id'].'.jpg'; //$postMedia['media']=$_SERVER['DOCUMENT_ROOT'].str_replace(array('./'),array('/'),$postMedia['media']); $filePath = CONF_PATH . 'img_' . $img['id'] . '.jpg'; $filePath = $_SERVER['DOCUMENT_ROOT'] . str_replace(array('./'), array('/'), $filePath); //CURLFile()只支援php5.6以上版本, $postMedia['media'] = new CURLFile($filePath); $rt = $this->curlPost('http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=' . $postMedia['access_token'] . '&type=' . $postMedia['type'], array('media' => $postMedia['media'])); if ($rt['rt'] == false) { $this->error('操作失敗,curl_error:' . $rt['errorno']); } else { $mediaids .= $rt['media_id']; $comma = ','; } }