代码如下:
$oss_sdk_service = new ALIOSS();
$oss_sdk_service->set_debug_mode(FALSE);
$bucket = 'xxxx';
$object = 'oss-file-name-'.time().'.jpg';
$pathFile = "C:/1.jpg";
$upload_file_options = array(
'content' => fopen($pathFile, 'r'),
'length' => filesize($pathFile),
);
$upload_file_by_content = $oss_sdk_service->upload_file_by_content($bucket,$object,$upload_file_options);
print_r($upload_file_by_content);die();
然后报错:
exception 'OSS_Exception' with message 'Http Body的内容非法',但是采用upload_file_by_file上传是可以的
解决如下:
你传入的是一个文件的句柄,并没有读取内容。应该改成这样:content' => file_get_contents($pathFile),