Skip to content

Commit d83a12e

Browse files
committed
Merge pull request #6 from Rican7/hotfix/buffer-creation-consistency
Hotfix - Buffer Creation Consistency Issues
2 parents 7f56a73 + 515fa8f commit d83a12e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/OneMightyRoar/PhpFileManager/FileObject.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,13 @@ public static function createFromBuffer($raw_binary_data, $name = null)
202202
// Must have the fileinfo extension loaded to automatically detect the MIME type
203203
}
204204

205+
// Only convert binary to hex if its not plain text
206+
if (strpos($mime_type, 'text') !== 0 || static::isBase64String($raw_binary_data)) {
207+
$raw_binary_data = bin2hex($raw_binary_data);
208+
}
209+
205210
// Wrap our binary data in a SplFileObject compatible data stream
206-
$stream_wrapped = 'data://'. $mime_type .','. bin2hex($raw_binary_data);
211+
$stream_wrapped = 'data://'. $mime_type .','. rawurlencode($raw_binary_data);
207212

208213
$object = new static($stream_wrapped, 'r');
209214
$object->setName($name);
@@ -716,8 +721,6 @@ public function getExtension($with_dot = false)
716721

717722
if (null !== $this->getName() && strpos($this->getName(), '.') !== false) {
718723
$extension = substr(strrchr($this->getName(), '.'), 1);
719-
} else {
720-
$extension = parent::getExtension();
721724
}
722725

723726
// Is our extension still "empty"?

0 commit comments

Comments
 (0)