<?php
/**
 * Created by PhpStorm.
 * User: Joseg
 * Date: 4/7/2018
 * Time: 12:47 AM
 */

class uploadImage
{
    public function subirImagen($imag){
        include '../uniqueNameGenerator/generateRamdonToken.php';
        $nombreGenerator = new generateRamdonToken();
        $nombreGenerated = $nombreGenerator->id();
        $directorio = $_SERVER['DOCUMENT_ROOT'].'/Api_MiResidenciAPP/uploads/';
        define('UPLOAD_DIR', $directorio);
        $img = $imag;
        $img = str_replace('data:image/jpeg;base64,', '', $img);
        $img = str_replace(' ', '+', $img);
        $data = base64_decode($img);
        $name= uniqid() . $nombreGenerated.'.jpg';
        $file = UPLOAD_DIR . $name;
        $success = file_put_contents($file, $data);
        $dire = 'http://www.joseg-dev.com.ve/Api_MiResidenciAPP/uploads/';
        $imagen = $dire.$name;
        return $imagen;


    }
}

