Don't keep $this->img in memory the whole time
This commit is contained in:
parent
04eefb7836
commit
3bbfabfd4b
|
@ -67,6 +67,15 @@ class ApiUpdateAvatarAction extends ApiAuthAction
|
||||||
$this->cropY = $this->trimmed('cropY');
|
$this->cropY = $this->trimmed('cropY');
|
||||||
$this->img = $this->trimmed('img');
|
$this->img = $this->trimmed('img');
|
||||||
|
|
||||||
|
$this->img = str_replace('data:image/jpeg;base64,', '', $this->img);
|
||||||
|
$this->img = str_replace('data:image/png;base64,', '', $this->img);
|
||||||
|
$this->img = str_replace(' ', '+', $this->img);
|
||||||
|
$this->img = base64_decode($this->img);
|
||||||
|
|
||||||
|
if (empty($this->img)) {
|
||||||
|
throw new ClientException(_('No uploaded image data.'));
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,21 +88,11 @@ class ApiUpdateAvatarAction extends ApiAuthAction
|
||||||
{
|
{
|
||||||
parent::handle();
|
parent::handle();
|
||||||
|
|
||||||
$base64img = $this->img;
|
|
||||||
$base64img = str_replace('data:image/jpeg;base64,', '', $base64img);
|
|
||||||
$base64img = str_replace('data:image/png;base64,', '', $base64img);
|
|
||||||
$base64img = str_replace(' ', '+', $base64img);
|
|
||||||
$base64img = base64_decode($base64img);
|
|
||||||
|
|
||||||
if (empty($base64img)) {
|
|
||||||
throw new ClientException(_('No uploaded image data.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$imagefile = null;
|
$imagefile = null;
|
||||||
// write the image to a temporary file
|
// write the image to a temporary file
|
||||||
$fh = tmpfile();
|
$fh = tmpfile();
|
||||||
fwrite($fh, $base64img);
|
fwrite($fh, $this->img);
|
||||||
unset($base64img); // no need to keep it in memory
|
unset($this->img); // no need to keep it in memory
|
||||||
// seek back to position 0, so we don't read EOF directly
|
// seek back to position 0, so we don't read EOF directly
|
||||||
fseek($fh, 0);
|
fseek($fh, 0);
|
||||||
// read the temporary file as an uploaded image, will store File object
|
// read the temporary file as an uploaded image, will store File object
|
||||||
|
|
Loading…
Reference in New Issue
Block a user