/** * 上传本地目录内的文件或者目录到指定bucket的指定prefix的object中 * * @param string $bucket bucket名称 * @param string $prefix 需要上传到的object的key前缀,可以理解成bucket中的子目录,结尾不能是'/',接口中会补充'/' * @param string $localDirectory 需要上传的本地目录 * @param string $exclude 需要排除的目录 * @param bool $recursive 是否递归的上传localDirectory下的子目录内容 * @param bool $checkMd5 * * @return array 返回两个列表 array("succeededList" => array("object"), "failedList" => array("object"=>"errorMessage")) * @throws Exception */ public function uploadDir($bucket, $prefix, $localDirectory, $exclude = '.|..|.svn|.git', $recursive = false, $checkMd5 = true) { $retArray = array("succeededList" => array(), "failedList" => array()); if (empty($bucket)) { throw new Exception("parameter error, bucket is empty"); } if (!is_string($prefix)) { throw new Exception("parameter error, prefix is not string"); } if (empty($localDirectory)) { throw new Exception("parameter error, localDirectory is empty"); } $directory = $localDirectory; $directory = Util::encodePath($directory); //判断是否目录 if (!is_dir($directory)) { throw new Exception('parameter error: ' . $directory . ' is not a directory, please check it'); } //read directory $file_list_array = Util::readDir($directory, $exclude, $recursive); if (!$file_list_array) { throw new Exception($directory . ' is empty...'); } foreach ($file_list_array as $k => $item) { if (is_dir($item['path'])) { continue; } $options = array(self::OSS_PART_SIZE => self::OSS_MIN_PART_SIZE, self::OSS_CHECK_MD5 => $checkMd5); $realObject = (!empty($prefix) ? $prefix . '/' : '') . $item['file']; try { $this->multiuploadFile($bucket, $realObject, $item['path'], $options); $retArray["succeededList"][] = $realObject; } catch (Exception $e) { $retArray["failedList"][$realObject] = $e->getMessage(); } } return $retArray; }
public function testReadDir() { $list = Util::readDir("./src", ".|..|.svn|.git", true); $this->assertNotNull($list); }