Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File & UploadFile Fixes #2104

Merged
merged 2 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions system/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ public function getMimeType(): string
*/
public function getRandomName(): string
{
return time() . '_' . bin2hex(random_bytes(10)) . '.' . $this->getExtension();
$extension = $this->getExtension();
$extension = empty($extension) ? '' : '.' . $extension;
return time() . '_' . bin2hex(random_bytes(10)) . $extension;
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -203,6 +205,7 @@ public function getDestination(string $destination, string $delimiter = '_', int
while (is_file($destination))
{
$info = pathinfo($destination);
$extension = isset($info['extension']) ? '.' . $info['extension'] : '';
if (strpos($info['filename'], $delimiter) !== false)
{
$parts = explode($delimiter, $info['filename']);
Expand All @@ -211,16 +214,16 @@ public function getDestination(string $destination, string $delimiter = '_', int
$i = end($parts);
array_pop($parts);
array_push($parts, ++ $i);
$destination = $info['dirname'] . '/' . implode($delimiter, $parts) . '.' . $info['extension'];
$destination = $info['dirname'] . '/' . implode($delimiter, $parts) . $extension;
}
else
{
$destination = $info['dirname'] . '/' . $info['filename'] . $delimiter . ++ $i . '.' . $info['extension'];
$destination = $info['dirname'] . '/' . $info['filename'] . $delimiter . ++ $i . $extension;
}
}
else
{
$destination = $info['dirname'] . '/' . $info['filename'] . $delimiter . ++ $i . '.' . $info['extension'];
$destination = $info['dirname'] . '/' . $info['filename'] . $delimiter . ++ $i . $extension;
}
}
return $destination;
Expand Down
6 changes: 3 additions & 3 deletions user_guide_src/source/libraries/uploaded_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ trusted version, use ``getExtension()`` instead::

$ext = $file->getClientExtension();

**getClientType()**
**getClientMimeType()**

Returns the mime type (mime type) of the file as provided by the client. This is NOT a trusted value. For a trusted
version, use ``getType()`` instead::
version, use ``getMimeType()`` instead::

$type = $file->getClientType();
$type = $file->getClientMimeType();

echo $type; // image/png

Expand Down