-
Notifications
You must be signed in to change notification settings - Fork 386
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
fix upload ContentType guess based on the key object file extension #232
base: master
Are you sure you want to change the base?
Conversation
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.
Linting failed (58986 errors, 325 warnings).
(59286 notices occurred in your codebase, but were on files/lines not included in this PR.)
@@ -187,10 +187,16 @@ public function stream_flush() | |||
$params = $this->getOptions(true); |
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.
Expected 1 spaces after opening bracket; 0 found
Expected 1 spaces before closing bracket; 0 found
@@ -187,10 +187,16 @@ public function stream_flush() | |||
$params = $this->getOptions(true); | |||
$params['Body'] = $this->body; | |||
|
|||
//Added by EveryUP Srl | |||
$objectKey = $params['Key']; |
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.
Variable "objectKey" is not in valid snake_case format
@@ -187,10 +187,16 @@ public function stream_flush() | |||
$params = $this->getOptions(true); | |||
$params['Body'] = $this->body; | |||
|
|||
//Added by EveryUP Srl | |||
$objectKey = $params['Key']; | |||
if(pathinfo($objectKey, PATHINFO_EXTENSION) == 'tmp') { |
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.
Expected 1 space(s) after IF keyword; 0 found
Space after opening control structure is required
No space before opening parenthesis is prohibited
No space after opening parenthesis is prohibited
Expected 1 spaces after opening bracket; 0 found
Expected 1 spaces before closing bracket; 0 found
Variable "objectKey" is not in valid snake_case format
Found: ==. Use strict comparisons (=== or !==).
No space before closing parenthesis is prohibited
// Attempt to guess the ContentType of the upload based on the | ||
// file extension of the key. Added by Joe Hoyle | ||
if (!isset($params['ContentType']) && | ||
($type = Psr7\mimetype_from_filename($params['Key'])) |
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.
Variable "objectKey" is not in valid snake_case format
Expected 1 spaces after opening bracket; 0 found
Expected 1 spaces before closing bracket; 0 found
Variable "objectKey" is not in valid snake_case format
if(pathinfo($objectKey, PATHINFO_EXTENSION) == 'tmp') { | ||
$objectKey = substr($objectKey, 0, -4); | ||
} | ||
|
||
// Attempt to guess the ContentType of the upload based on the | ||
// file extension of the key. Added by Joe Hoyle | ||
if (!isset($params['ContentType']) && |
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.
No space after opening parenthesis is prohibited
Expected 1 space before "!"; 0 found
Expected 1 space after "!"; 0 found
Expected 1 spaces after opening bracket; 0 found
Expected 1 spaces before closing bracket; 0 found
// Attempt to guess the ContentType of the upload based on the | ||
// file extension of the key. Added by Joe Hoyle | ||
if (!isset($params['ContentType']) && | ||
($type = Psr7\mimetype_from_filename($params['Key'])) | ||
($type = Psr7\mimetype_from_filename($objectKey)) |
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.
Assignments must be the first block of code on a line
Expected 1 spaces after opening bracket; 0 found
Expected 1 spaces before closing bracket; 0 found
Variable "objectKey" is not in valid snake_case format
@zvfvrv could you point me to where in WordPress Core the |
Hi @joehoyle , |
Hmm ok, seems like we need to investigate if this behavior is from Core or potentially a plugin, etc. |
@joehoyle i investigated on a wp instance with the issue, perhaps the problem is related to a plugin for image optimization WP SMUSH. |
@joehoyle for a start, perhaps see wp-admin/includes/file.php L610 (and wp-smushit/lib/class-wpsmush.php L248) |
wordpress append the .tmp extension to filenames when generating thumbnails. E.g.
-150x150.jpg.tmp
So when guessing the ContentType from the extension the Psr7\mimetype_from_filename() will not work properly.
To avoid this issue, we strip the .tmp extension if present.