Core: Windows loses image file extensions

Created on 29 Mar 2016  路  3Comments  路  Source: flarum/core

As per this topic at discuss.flarum

It seems like Flarum is saving the image file to a .tmp extension, but while Linux can recover the true extension and finish the upload, Windows loses its mind and produces a 500 error instead.

typbug

Most helpful comment

Discussion of the cause and workarounds begins at post 16 of that thread.

All 3 comments

Discussion of the cause and workarounds begins at post 16 of that thread.

The real answer begins at post 24 of the above mentioned thread.
It is proved that creating a temp file with .jpg extension instead of .tmp solves the problem in Windows. No problem if the file is really a gif, png or jpg file, it works for all three types.

Suggested solution :
in project/vendor/flarum/core/src/Core/Command/UploadAvatarHandler.php

$tmpFile = $this->app->storagePath().'/tmp/avatar' . rand() . '-tmp.jpg' 
$command->file->moveTo($tmpFile);

It works for the three image types, jpg, gif and png.
In case you would really prefer to have the right extension, you could use getClientOriginalExtension(), But it does not seem necessary.
Works fine in Windows7 and Flarum beta-5

Was this page helpful?
0 / 5 - 0 ratings

Related issues

franzliedke picture franzliedke  路  4Comments

luceos picture luceos  路  3Comments

matteocontrini picture matteocontrini  路  3Comments

clrh picture clrh  路  4Comments

tobyzerner picture tobyzerner  路  5Comments