使用下面的代码$filename总是要求是框架下的Public路径而抛出设置的异常资源路径错误,注释掉异常抛出还是不能上传成功dump出false,当我在框架指定的Public/uploads目录下放入image.jpg图片时则能上传成功!
使用$st = new \SaeStorage(); $filename = $st->getUrl('public', '/uploads/image.jpg');还是dump出false,实在是不知道怎么办,请大神们帮帮小弟!
$filename='./Public/uploads/image.jpg';
$type = 'image';
public function addMaterial($filename, $type, $description = ''){
$filename = realpath($filename);
if (!$filename){
throw new \Exception('资源路径错误');
}
$data = array(
'type' => $type,
'media' => "@".$filename,
);
if ($type == 'video'){
//微信API不支持中文转移的json结构,所以保护中文
if (is_array($description)){
array_walk_recursive($description, function(&$value){
$value = urlencode($value);
});
$description = urldecode(json_encode($description));
}
$data['description'] = $description;
}
$access_token = $this->getAccessTokenFromMysql();
$url = implode(array($this->apiURL, '/material/add_material?access_token=', $access_token));
$arr = $this->sendCurl($url, 'POST', $data);
var_dump($arr);
} 最佳答案