-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add support for a list of allowed mime-types instead of only one #50
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,7 +6,7 @@ | |||||
'secretBcrypt' => '', | ||||||
'saveDirName' => '/data/', | ||||||
'maxScreenshotSize' => 2 * 1048576, | ||||||
'screenshotMimeType' => 'image/png' | ||||||
'screenshotMimeTypes' => [ 'image/png', 'image/jpeg' ] | ||||||
], | ||||||
file_exists('./config.php') ? include_once('./config.php') : [] | ||||||
); | ||||||
|
@@ -20,21 +20,22 @@ | |||||
exit(); | ||||||
} | ||||||
|
||||||
$mimetype = isset($screenshot['tmp_name']) ? mime_content_type($screenshot['tmp_name']) : "error"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if ( | ||||||
// Make sure it is a successful single file upload | ||||||
!isset($screenshot['error']) || | ||||||
is_array($screenshot['error']) || | ||||||
$screenshot['error'] !== UPLOAD_ERR_OK || | ||||||
// Verify size and mime type | ||||||
$screenshot['size'] > $config['maxScreenshotSize'] || | ||||||
mime_content_type($screenshot['tmp_name']) !== $config['screenshotMimeType'] | ||||||
!in_array( $mimetype, $config['screenshotMimeTypes'], true) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) { | ||||||
http_response_code(422); | ||||||
exit(); | ||||||
} | ||||||
|
||||||
// Generate screenshot path | ||||||
do {} while (file_exists($filename = bin2hex(random_bytes(12)) . '.png')); | ||||||
do {} while (file_exists($filename = bin2hex(random_bytes(12)) . '.' . ($mimetype == "image/png" ? "png" : "jpg" ))); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone adds other mimetypes besides these 2, I guess we can't really have this assumption of using |
||||||
|
||||||
// Create save directory and move screenshot to it | ||||||
if ( | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.