$mediaId = 'xxxxxxxxxx'; $accessToken = getAccessToken($_C['appId'],$_C['appSecret']); $downloadApi = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$accessToken}&media_id={$mediaId}"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $downloadApi); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $fileName = 'filename.jpg'; @chmod($fileName,777); $handle = fopen($fileName,'wb'); fwrite($handle, $output); fclose($handle);