<?php
class ImageUpload{


function uploadImage($filename,$data){
    
    date_default_timezone_set('Asia/Calcutta');
    $folder = "../../workreportimages/";
    if(!file_exists($folder)){
        mkdir($folder);
    }
    $datetime=date('YmdHis');
    if(empty($data)){
    echo $filename;
    }
    $imageName = $filename.".jpg";
    $iamgePath = $folder.$imageName;

    if(!file_exists($iamgePath)){
        $imageName = $filename."1.jpg";
        $iamgePath = $folder.$imageName;
    }
    

    $imageData = base64_decode($data);
    $source = imagecreatefromstring($imageData);
    //$rotate = imagerotate($source, $angle, 0); // if want to rotate the image
    $imageSave = imagejpeg($rotate,$iamgePath,100);
    imagedestroy($source);
    
    return $imageName;
} 

function uploadImage2($filename,$data){
    
    date_default_timezone_set('Asia/Calcutta');
    $folder = "../../fieldcloudimages/";
    if(!file_exists($folder)){
        mkdir($folder);
    }
    $datetime=date('YmdHis');
    if(empty($data)){
    echo $filename;
    }
    $imageName = $filename.".jpg";
    $iamgePath = $folder.$imageName;

    if(!file_exists($iamgePath)){
        $imageName = $filename."1.jpg";
        $iamgePath = $folder.$imageName;
    }
    

    $imageData = base64_decode($data);
    $source = imagecreatefromstring($imageData);
    $rotate = imagerotate($source, $angle, 0); // if want to rotate the image
    $imageSave = imagejpeg($rotate,$iamgePath,100);
    imagedestroy($source);
    return $imageName;
} 
function uploadImage2_c($filename,$data){
    
    date_default_timezone_set('Asia/Calcutta');
    $folder = "../../fieldcloudimages/";
    if(!file_exists($folder)){
        mkdir($folder);
    }
    $datetime=date('YmdHis');
    if(empty($data)){
    echo $filename;
    }
    $imageName = $filename.".jpg";
    $iamgePath = $folder.$imageName;

    if(!file_exists($iamgePath)){
        $imageName = $filename."1.jpg";
        $iamgePath = $folder.$imageName;
    }
    

    $imageData = base64_decode($data);
    $source = imagecreatefromstring($imageData);
    //$rotate = imagerotate($source, $angle, 0); // if want to rotate the image
    $imageSave = imagejpeg($rotate,$iamgePath,100);
    imagedestroy($source);
    
    return $imageName;
} 

}
?>