PHP1.0版本上传OSS报错,仿照2.0版本传入的居然是句柄

代码如下: 
 
        $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),

posted @ 2014-11-17 14:26  腐烂的翅膀  阅读(270)  评论(0编辑  收藏  举报