diff --git a/samples/Image.php b/samples/Image.php index 6e51d06d..85317339 100644 --- a/samples/Image.php +++ b/samples/Image.php @@ -83,5 +83,5 @@ function printImage($func, $imageFile) Common::println("$func, image width: " . $array[0]); Common::println("$func, image height: " . $array[1]); Common::println("$func, image type: " . ($array[2] === 2 ? 'jpg' : 'png')); - Common::println("$func, image size: " . ceil(filesize($imageFile))); + Common::println("$func, image size: " . ceil(sprintf('%u',filesize($imageFile)))); } diff --git a/samples/MultipartUpload.php b/samples/MultipartUpload.php index 21756b7c..dd4b7fde 100644 --- a/samples/MultipartUpload.php +++ b/samples/MultipartUpload.php @@ -85,7 +85,7 @@ function putObjectByRawApis($ossClient, $bucket) */ $partSize = 10 * 1024 * 1024; $uploadFile = __FILE__; - $uploadFileSize = filesize($uploadFile); + $uploadFileSize = sprintf('%u',filesize($uploadFile)); $pieces = $ossClient->generateMultiuploadParts($uploadFileSize, $partSize); $responseUploadPart = array(); $uploadPosition = 0; diff --git a/samples/Signature.php b/samples/Signature.php index eef59812..6388f270 100644 --- a/samples/Signature.php +++ b/samples/Signature.php @@ -130,7 +130,7 @@ function getSignedUrlForPuttingObjectFromFile($ossClient, $bucket) $request->set_method('PUT'); $request->add_header('Content-Type', 'txt'); $request->set_read_file($file); - $request->set_read_stream_size(filesize($file)); + $request->set_read_stream_size(sprintf('%u',filesize($file))); $request->send_request(); $res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code()); diff --git a/src/OSS/Core/OssUtil.php b/src/OSS/Core/OssUtil.php index e3f2037f..2e005d67 100644 --- a/src/OSS/Core/OssUtil.php +++ b/src/OSS/Core/OssUtil.php @@ -237,7 +237,7 @@ public static function throwOssExceptionWithMessageIfEmpty($name, $errMsg) */ public static function generateFile($filename, $size) { - if (file_exists($filename) && $size == filesize($filename)) { + if (file_exists($filename) && $size == sprintf('%u',filesize($filename))) { echo $filename . " already exists, no need to create again. "; return; } @@ -284,7 +284,7 @@ public static function getMd5SumForFile($filename, $from_pos, $to_pos) if (($to_pos - $from_pos) > self::OSS_MAX_PART_SIZE) { return $content_md5; } - $filesize = filesize($filename); + $filesize = sprintf('%u',filesize($filename)); if ($from_pos >= $filesize || $to_pos >= $filesize || $from_pos < 0 || $to_pos < 0) { return $content_md5; } diff --git a/src/OSS/Model/ObjectInfo.php b/src/OSS/Model/ObjectInfo.php index 891f8625..4adab3ca 100644 --- a/src/OSS/Model/ObjectInfo.php +++ b/src/OSS/Model/ObjectInfo.php @@ -23,7 +23,7 @@ class ObjectInfo * @param string $lastModified * @param string $eTag * @param string $type - * @param int $size + * @param string $size * @param string $storageClass */ public function __construct($key, $lastModified, $eTag, $type, $size, $storageClass) @@ -67,15 +67,26 @@ public function getType() { return $this->type; } - - /** - * @return int - */ - public function getSize() - { - return $this->size; - } - + + /** + * php7 && 64bit can use it + * @return int + */ + public function getSize() + { + return (int)$this->size; + } + + + /** + * php5.x or 32bit must use it + * @return string + */ + public function getSizeStr() + { + return $this->size; + } + /** * @return string */ @@ -88,6 +99,6 @@ public function getStorageClass() private $lastModified = ""; private $eTag = ""; private $type = ""; - private $size = 0; + private $size = "0"; private $storageClass = ""; } \ No newline at end of file diff --git a/src/OSS/Model/ObjectVersionInfo.php b/src/OSS/Model/ObjectVersionInfo.php index 407315d2..663bd0b3 100644 --- a/src/OSS/Model/ObjectVersionInfo.php +++ b/src/OSS/Model/ObjectVersionInfo.php @@ -23,7 +23,7 @@ class ObjectVersionInfo * @param string $lastModified * @param string $eTag * @param string $type - * @param int $size + * @param string $size * @param string $storageClass * @param string $isLatest */ @@ -78,14 +78,25 @@ public function getType() { return $this->type; } - - /** - * @return int - */ - public function getSize() - { - return $this->size; - } + + /** + * php7 && 64bit can use it + * @return int + */ + public function getSize() + { + return (int)$this->size; + } + + + /** + * php5.x or 32bit must use it + * @return string + */ + public function getSizeStr() + { + return $this->size; + } /** * @return string @@ -108,7 +119,7 @@ public function getIsLatest() private $lastModified = ""; private $eTag = ""; private $type = ""; - private $size = 0; + private $size = "0"; private $storageClass = ""; private $isLatest = ""; } \ No newline at end of file diff --git a/src/OSS/Model/PartInfo.php b/src/OSS/Model/PartInfo.php index 439a84d3..07df5768 100644 --- a/src/OSS/Model/PartInfo.php +++ b/src/OSS/Model/PartInfo.php @@ -14,7 +14,7 @@ class PartInfo * @param int $partNumber * @param string $lastModified * @param string $eTag - * @param int $size + * @param string $size */ public function __construct($partNumber, $lastModified, $eTag, $size) { @@ -49,15 +49,26 @@ public function getETag() } /** + * php7 && 64bit can use it * @return int */ public function getSize() { - return $this->size; + return (int)$this->size; } + + + /** + * php5.x or 32bit must use it + * @return string + */ + public function getSizeStr() + { + return $this->size; + } private $partNumber = 0; private $lastModified = ""; private $eTag = ""; - private $size = 0; + private $size = "0"; } \ No newline at end of file diff --git a/src/OSS/OssClient.php b/src/OSS/OssClient.php index c41cacda..8e558bce 100644 --- a/src/OSS/OssClient.php +++ b/src/OSS/OssClient.php @@ -1698,7 +1698,7 @@ public function uploadFile($bucket, $object, $file, $options = NULL) throw new OssException($file . " file does not exist"); } $options[self::OSS_FILE_UPLOAD] = $file; - $file_size = filesize($options[self::OSS_FILE_UPLOAD]); + $file_size = sprintf('%u',filesize($options[self::OSS_FILE_UPLOAD])); $is_check_md5 = $this->isCheckMD5($options); if ($is_check_md5) { $content_md5 = base64_encode(md5_file($options[self::OSS_FILE_UPLOAD], true)); @@ -1816,7 +1816,7 @@ public function appendFile($bucket, $object, $file, $position, $options = NULL) throw new OssException($file . " file does not exist"); } $options[self::OSS_FILE_UPLOAD] = $file; - $file_size = filesize($options[self::OSS_FILE_UPLOAD]); + $file_size = sprintf('%u',filesize($options[self::OSS_FILE_UPLOAD])); $is_check_md5 = $this->isCheckMD5($options); if ($is_check_md5) { $content_md5 = base64_encode(md5_file($options[self::OSS_FILE_UPLOAD], true)); @@ -2460,7 +2460,8 @@ public function multiuploadFile($bucket, $object, $file, $options = null) if (isset($options[self::OSS_CONTENT_LENGTH])) { $upload_file_size = (integer)$options[self::OSS_CONTENT_LENGTH]; } else { - $upload_file_size = filesize($uploadFile); + $upload_file_size = sprintf('%u',filesize($uploadFile)); + if ($upload_file_size !== false) { $upload_file_size -= $upload_position; } diff --git a/src/OSS/Result/ListObjectVersionsResult.php b/src/OSS/Result/ListObjectVersionsResult.php index 5f18c4df..849c21c2 100644 --- a/src/OSS/Result/ListObjectVersionsResult.php +++ b/src/OSS/Result/ListObjectVersionsResult.php @@ -56,7 +56,7 @@ private function parseObjecVersionList($xml, $encodingType) $lastModified = isset($content->LastModified) ? strval($content->LastModified) : ""; $eTag = isset($content->ETag) ? strval($content->ETag) : ""; $type = isset($content->Type) ? strval($content->Type) : ""; - $size = isset($content->Size) ? intval($content->Size) : 0; + $size = isset($content->Size) ? strval($content->Size) : "0"; $storageClass = isset($content->StorageClass) ? strval($content->StorageClass) : ""; $isLatest = isset($content->IsLatest) ? strval($content->IsLatest) : ""; $retList[] = new ObjectVersionInfo($key, $versionId, $lastModified, $eTag, $type, $size, $storageClass, $isLatest); diff --git a/src/OSS/Result/ListObjectsResult.php b/src/OSS/Result/ListObjectsResult.php index f44c66a0..39f1f292 100644 --- a/src/OSS/Result/ListObjectsResult.php +++ b/src/OSS/Result/ListObjectsResult.php @@ -48,7 +48,7 @@ private function parseObjectList($xml, $encodingType) $lastModified = isset($content->LastModified) ? strval($content->LastModified) : ""; $eTag = isset($content->ETag) ? strval($content->ETag) : ""; $type = isset($content->Type) ? strval($content->Type) : ""; - $size = isset($content->Size) ? intval($content->Size) : 0; + $size = isset($content->Size) ? strval($content->Size) : "0"; $storageClass = isset($content->StorageClass) ? strval($content->StorageClass) : ""; $retList[] = new ObjectInfo($key, $lastModified, $eTag, $type, $size, $storageClass); } diff --git a/src/OSS/Result/ListPartsResult.php b/src/OSS/Result/ListPartsResult.php index 092d94e0..6641b5bb 100644 --- a/src/OSS/Result/ListPartsResult.php +++ b/src/OSS/Result/ListPartsResult.php @@ -33,7 +33,7 @@ protected function parseDataFromResponse() $partNumber = isset($part->PartNumber) ? intval($part->PartNumber) : ""; $lastModified = isset($part->LastModified) ? strval($part->LastModified) : ""; $eTag = isset($part->ETag) ? strval($part->ETag) : ""; - $size = isset($part->Size) ? intval($part->Size) : ""; + $size = isset($part->Size) ? strval($part->Size) : ""; $partList[] = new PartInfo($partNumber, $lastModified, $eTag, $size); } } diff --git a/tests/OSS/Tests/OssClientMultipartUploadTest.php b/tests/OSS/Tests/OssClientMultipartUploadTest.php index 8f406548..0e861624 100644 --- a/tests/OSS/Tests/OssClientMultipartUploadTest.php +++ b/tests/OSS/Tests/OssClientMultipartUploadTest.php @@ -172,7 +172,7 @@ public function testAbortMultipartUpload() */ $part_size = 10 * 1024 * 1024; $upload_file = __FILE__; - $upload_filesize = filesize($upload_file); + $upload_filesize = sprintf('%u',filesize($upload_file)); $pieces = $this->ossClient->generateMultiuploadParts($upload_filesize, $part_size); $response_upload_part = array(); $upload_position = 0; @@ -257,7 +257,7 @@ public function testPutObjectByRawApis() */ $part_size = 10 * 1024 * 1024; $upload_file = __FILE__; - $upload_filesize = filesize($upload_file); + $upload_filesize = sprintf('%u',filesize($upload_file)); $pieces = $this->ossClient->generateMultiuploadParts($upload_filesize, $part_size); $response_upload_part = array(); $upload_position = 0; diff --git a/tests/OSS/Tests/OssClientObjectRequestPaymentTest.php b/tests/OSS/Tests/OssClientObjectRequestPaymentTest.php index 41e18cf1..66251880 100644 --- a/tests/OSS/Tests/OssClientObjectRequestPaymentTest.php +++ b/tests/OSS/Tests/OssClientObjectRequestPaymentTest.php @@ -354,7 +354,7 @@ public function testMultipartOperationsWithRequester() */ $part_size = 1 * 1024 * 1024; $upload_file = __FILE__; - $upload_filesize = filesize($upload_file); + $upload_filesize = sprintf('%u',filesize($upload_file)); $pieces = $this->payerClient->generateMultiuploadParts($upload_filesize, $part_size); $response_upload_part = array(); $upload_position = 0; diff --git a/tests/OSS/Tests/OssClientObjectTest.php b/tests/OSS/Tests/OssClientObjectTest.php index 228a394d..bb610188 100644 --- a/tests/OSS/Tests/OssClientObjectTest.php +++ b/tests/OSS/Tests/OssClientObjectTest.php @@ -398,9 +398,9 @@ public function testAppendObject() */ try { $position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, 0); - $this->assertEquals($position, filesize(__FILE__)); + $this->assertEquals($position, sprintf('%u',filesize(__FILE__))); $position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, $position); - $this->assertEquals($position, filesize(__FILE__) * 2); + $this->assertEquals($position, sprintf('%u',filesize(__FILE__)) * 2); } catch (OssException $e) { $this->assertFalse(true); } @@ -568,9 +568,9 @@ public function testCheckMD5() */ try { $position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, 0, $options); - $this->assertEquals($position, filesize(__FILE__)); + $this->assertEquals($position, sprintf('%u',filesize(__FILE__))); $position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, $position, $options); - $this->assertEquals($position, filesize(__FILE__) * 2); + $this->assertEquals($position, sprintf('%u',filesize(__FILE__)) * 2); } catch (OssException $e) { $this->assertFalse(true); } diff --git a/tests/OSS/Tests/OssClientSignatureTest.php b/tests/OSS/Tests/OssClientSignatureTest.php index f5beb488..786a6231 100644 --- a/tests/OSS/Tests/OssClientSignatureTest.php +++ b/tests/OSS/Tests/OssClientSignatureTest.php @@ -64,7 +64,7 @@ public function testGetSignedUrlForPuttingObjectFromFile() $request->set_method('PUT'); $request->add_header('Content-Type', 'txt'); $request->set_read_file($file); - $request->set_read_stream_size(filesize($file)); + $request->set_read_stream_size(sprintf('%u',filesize($file))); $request->send_request(); $res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code()); diff --git a/tests/OSS/Tests/OssUtilTest.php b/tests/OSS/Tests/OssUtilTest.php index 85ee07b9..598a7cc5 100644 --- a/tests/OSS/Tests/OssUtilTest.php +++ b/tests/OSS/Tests/OssUtilTest.php @@ -154,10 +154,10 @@ public function testReadDir() public function testGetMd5SumForFile() { - $this->assertEquals(OssUtil::getMd5SumForFile(__FILE__, 0, filesize(__FILE__) - 1), base64_encode(md5(file_get_contents(__FILE__), true))); + $this->assertEquals(OssUtil::getMd5SumForFile(__FILE__, 0, sprintf('%u',filesize(__FILE__)) - 1), base64_encode(md5(file_get_contents(__FILE__), true))); // false case $this->assertEquals(OssUtil::getMd5SumForFile(__FILE__, 0, OssClient::OSS_MAX_PART_SIZE + 1), ""); - $this->assertEquals(OssUtil::getMd5SumForFile(__FILE__, 0, filesize(__FILE__) + 1), ""); + $this->assertEquals(OssUtil::getMd5SumForFile(__FILE__, 0, sprintf('%u',filesize(__FILE__)) + 1), ""); } @@ -165,7 +165,7 @@ public function testGenerateFile() { $path = __DIR__ . DIRECTORY_SEPARATOR . "generatedFile.txt"; OssUtil::generateFile($path, 1024 * 1024); - $this->assertEquals(filesize($path), 1024 * 1024); + $this->assertEquals(sprintf('%u',filesize($path)), 1024 * 1024); unlink($path); }