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

fix upload ContentType guess based on the key object file extension #232

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zvfvrv
Copy link

@zvfvrv zvfvrv commented Apr 10, 2018

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.

Copy link

@hm-linter hm-linter bot left a 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);
Copy link

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'];
Copy link

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') {
Copy link

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']))
Copy link

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']) &&
Copy link

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))
Copy link

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

@joehoyle
Copy link
Member

@zvfvrv could you point me to where in WordPress Core the tmp is applied? Thanks!

@zvfvrv
Copy link
Author

zvfvrv commented Apr 10, 2018

Hi @joehoyle ,
unfortunately i dunno, i realized that for each thumbnails automatically generated from wordpress, the value of $params['Key'] is like filename-150x150.jpg.tmp or filename-600x486.png.tmp.
Regards.

@joehoyle
Copy link
Member

Hmm ok, seems like we need to investigate if this behavior is from Core or potentially a plugin, etc.

@zvfvrv
Copy link
Author

zvfvrv commented Apr 10, 2018

@joehoyle i investigated on a wp instance with the issue, perhaps the problem is related to a plugin for image optimization WP SMUSH.

@wp-networks
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants