function upload($source, $target)
{
try {
$file = new UpyunMultiPartFile($source);
} catch (Exception $e) {
return 0;
}
if ($file->getSize() > 1024 * 1024 && $this->upyun_config['form_api_key']) {
$sign = new UpyunMultipartSignature($this->upyun_config['form_api_key']);
$upload = new UpyunMultipartUpload($sign);
$upload->setBucketName($this->upyun_config['bucket_name']);
$upload->setBlockSize($upload->getBlockSizeAdaptive($file));
try {
$result = $upload->upload($file, array('path' => $this->upyun_dir . ltrim($target, '/')));
return $result;
} catch (Exception $e) {
return 0;
}
} else {
$fh = fopen($source, 'rb');
if (!$fh) {
return 0;
}
$upyun = new UpYun($this->upyun_config['bucket_name'], $this->upyun_config['operator_name'], $this->upyun_config['operator_pwd']);
$rsp = $upyun->writeFile($this->upyun_dir . ltrim($target, '/'), $fh, true);
return $rsp;
}
}