Attached simple code that I use. You have to develop code php to compress photos ($photo). For example, a photo that weighs 400KB have to reduce it to 40-80KB without losing quality, with the same size.
It is necessary that the image is compressed before save Image in the path.
I use a linux server centos7.
private function saveImage($image, $path, $name)
$file = fopen($path.'/'.$name, 'wb');
public function uploadPhoto($photo)
$this->saveImage(base64_decode($photo), 'images/tags', $name.$this->EXTENSION_JPG);