<?php
class ImageUpload{

function uploadImage($companyId,$travelId,$data){
    
    date_default_timezone_set('Asia/Calcutta');
    $imageFolder="hcmExpImg/".$companyId;
    
    $year=date('Y');
    $month=date('m');
    
    //dynamic folders creation starts
   
    $folder = "../../$imageFolder/";
    if(!file_exists($folder)){
        mkdir($folder);
    }
                
    $folder = "../../$imageFolder/$year/";
    if(!file_exists($folder)){
        mkdir($folder);
    }
                
    $folder = "../../$imageFolder/$year/$month/";
    if(!file_exists($folder)){
        mkdir($folder);
    }
    
    $folder = "../../$imageFolder/$year/$month/";
    if(!file_exists($folder)){
        mkdir($folder);
    }
    
    $datetime=date('YmdHis');

    //Dynamic folder creation ends
    $imageName = $folder.$travelId.$datetime.".jpg";
    
    if(!file_exists($imageName)){
        $imageName = $folder.$travelId.$datetime."1.jpg";
    }
    
    $imageData = base64_decode($data);
    $source = imagecreatefromstring($imageData);
    $rotate = imagerotate($source, $angle, 0); // if want to rotate the image
    $imageSave = imagejpeg($rotate,$imageName,100);
    imagedestroy($source);
    
    return str_replace("../","",$imageName);
} 

}
?>