//上传本地文件到阿里 public function uploadFile($object, $file_path,$options = null) { $bucket_name = self::bucket; //bucket名字 $oss = self::gitInstance(); //oss对象 // $object = trim('static/'.$name); //阿里文件路径 $options = array( 'fileUpload' => $file_path, //本地路径 'partSize' => 5242880, ); //分流文件上传,调用sdk.class.php中的方法 $response = $oss->create_mpu_object($bucket_name, $object, $options); //第二种方法调用,通过内容上传 /*$handle = fopen($file_path, 'r'); $contents = fread($handle,filesize($file_path)); fclose($handle); $options = array( 'content' => $contents, 'length' => strlen($file_path), ); $response = $oss->upload_file_by_content($bucket_name, $object, $options);*/ // var_dump($response); return $response; }
/** * 上传整个目录,通过multi-part,通过该方式创建的object默认为文件名 * $oss_sdk_service->create_mtu_object_by_dir($bucket,$dir,$recursive = false,$exclude = ".|..|.svn",$options = null) * 其中$bucket,$dir为必选参数,$recursive,$exclude,$options可选,其中o * $bucket 为bucket名称 * $dir 某一目录 * $recursive 该参数设置是否递归读取目录。 * $exclude 要过滤掉的文件,默认为系统默认生成的.,..,和svn文件.svn */ $bucket = 'php-sdk-windows'; $dir = "C:\\Windows"; $recursive = true; $create_mtu_object_by_dir_response = $oss_sdk_service->create_mtu_object_by_dir($bucket,$dir,$recursive); print_r($create_mtu_object_by_dir_response);die();/*上传图片文件,$object_name图片名称,$file_path图片本地路径*/ public static function upload($object_name, $file_path, $options = null) { $bucket_name = self::bucket; $oss = self::gitInstance(); $options = array(); $response = $oss->upload_file_by_file($bucket_name, $object_name, $file_path, $options); return $response; }