开发者社区 问答 正文

PHP1.0版本上传OSS报错,大家帮忙解决下啊

代码如下:

        $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上传是可以的,可是项目需要采用binary的上传方式, 请大家帮我看看是怎么回事,谢谢



展开
收起
幻灵游侠 2014-11-11 10:49:41 6824 分享 版权
1 条回答
写回答
取消 提交回答
  • 回楼主幻灵游侠的帖子
            if(isset($options[self::OSS_CONTENT])){
                if($options[self::OSS_CONTENT] == '' || !is_string($options[self::OSS_CONTENT])){
                    throw new OSS_Exception(OSS_INVALID_HTTP_BODY_CONTENT,'-600');

    这段代码的意思就是你传入的不是一个string
    从你的代码来看,你传入的是一个文件的句柄,并没有读取内容。应该改成这样:content' => file_get_contents($pathFile),
    2014-11-11 16:43:44
    赞同 展开评论