Skip to content

Commit 31646fe

Browse files
committed
Make inputResource() find the buffer length when set to false
1 parent a938ec8 commit 31646fe

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

S3.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,25 @@ public static function inputFile($file, $md5sum = true)
545545
* @param string $md5sum MD5 hash to send (optional)
546546
* @return array | false
547547
*/
548-
public static function inputResource(&$resource, $bufferSize, $md5sum = '')
548+
public static function inputResource(&$resource, $bufferSize = false, $md5sum = '')
549549
{
550-
if (!is_resource($resource) || $bufferSize < 0)
550+
if (!is_resource($resource) || (int)$bufferSize < 0)
551551
{
552552
self::__triggerError('S3::inputResource(): Invalid resource or buffer size', __FILE__, __LINE__);
553553
return false;
554554
}
555+
556+
// Try to figure out the bytesize
557+
if ($bufferSize === false)
558+
{
559+
if (fseek($resource, 0, SEEK_END) < 0 || ($bufferSize = ftell($resource)) === false)
560+
{
561+
self::__triggerError('S3::inputResource(): Unable to obtain resource size', __FILE__, __LINE__);
562+
return false;
563+
}
564+
fseek($resource, 0);
565+
}
566+
555567
$input = array('size' => $bufferSize, 'md5sum' => $md5sum);
556568
$input['fp'] =& $resource;
557569
return $input;

0 commit comments

Comments
 (0)