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 : 3.146.255.161


Current Path : /proc/thread-self/root/var/www/html/cnv/rcub/custom_src/
Upload File :
Current File : //proc/thread-self/root/var/www/html/cnv/rcub/custom_src/admin.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');

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

function downloadstudentphotozip($aobj_context)
{
	//session_start();
	//echo "string";

$FUNIVCODE = '023';

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

	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
	$fromdate = $aobj_context->mobj_data["fromdate"]; 
	$todate = $aobj_context->mobj_data["todate"]; 

	$query = "select dctran.FPHOTOPATH,concat(EXTRACT(YEAR from '{$fromdate}'),EXTRACT(MONTH from '{$fromdate}'),
	EXTRACT(DAY from '{$fromdate}'),'_',EXTRACT(YEAR from '{$todate}'),EXTRACT(MONTH from '{$todate}'),EXTRACT(DAY from '{$todate}')) as dateFormat from  
	dctran
	where  DATE_FORMAT(dctran.FREGDATE,'%Y-%m-%d') between '{$fromdate}' and '{$todate}' AND IFNULL(dctran.FPHOTOPATH,'') != ''
	and ifnull(fpaystatus,'') = 'success'";
	$lobj_get_studentInfo = $aobj_context->mobj_db->getAll($query);

	$desDirectry = $aobj_context->main_src."/tmpphotos/".$lobj_get_studentInfo[0]['dateFormat']."/";
	$photoDownloadCnt=0;
	//var_dump($lobj_get_studentInfo);
	foreach($lobj_get_studentInfo as $key=>$value)
	{
		$fURI  ='';
		$photo_path = $value['FPHOTOPATH'];
		
		$file_name=replaceChars(basename($photo_path));
		
		$fURI = 'cnv/'.$FUNIVCODE.'/'.$photo_path;
		
		if(!is_dir($desDirectry))
		{
			mkdir($desDirectry);
			chmod($desDirectry,0777);
		}
	
		$full_file_path= $desDirectry.$file_name;
		//var_dump($full_file_path);die();
		
			
			$target_file = $full_file_path;//   Path to a local file   
			//var_dump($target_file);die();
			if (file_exists( $target_file )) 
			{
				$ifmodhdr = 'If-Modified-Since: '.date( "r", filemtime( $target_file ) )."\r\n";
			}
			else 
			{
				$ifmodhdr = '';
			}
		   		
			//$rc = copy( $fURI, $target_file);
			try {
				$rc = $s3->getObject(['Bucket' => STUDENT_PHOTOS_BUCKET, 'Key' => $fURI, 'SaveAs' => $target_file]);
			} catch(S3Exception $e) {
				$excepted = true;
				// Assert::assertEquals('NoSuchKey', $e->getAwsErrorCode());
			} finally {
					// Assert::assertTrue($excepted);
			}
			// if($rc) 
			// {
			// 	$photoDownloadCnt++;
			// 	if ( fclose( $rc ) )
			// 	{
			// 		unset( $err );		
			// 	}
			// 	else 
			// 	{
			// 		$err = error_get_last();
			// 	}
			// }
			// else
			// {
			// 	$err = error_get_last();
			// }
			

	} 
	$the_folder = $desDirectry;
	$zip_file_name = "tmpphotos/kus_"."{$lobj_get_studentInfo[0]['dateFormat']}.zip";

	//var_dump($zip_file_name);
	
	$download_file= true;
	// $command    = "zip -r ".$zip_file_name." tmpphotos/".$lobj_get_studentInfo[0]['dateFormat'];
	// $res = exec($command);
	$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)
	{
		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);
	}
}


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

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);
		}
	} 
}



function downloadstudentphotos($aobj_context)
{
	//echo "hello";
	/*session_start();
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
	$fromdate = $aobj_context->mobj_data["fromdate"]; 
	$todate = $aobj_context->mobj_data["todate"]; 

	$query = "select dctran.FPHOTOPATH,concat(EXTRACT(YEAR from '{$fromdate}'),EXTRACT(MONTH from '{$fromdate}'),EXTRACT(DAY from '{$fromdate}'),'_',EXTRACT(YEAR from '{$todate}'),EXTRACT(MONTH from '{$todate}'),EXTRACT(DAY from '{$todate}')) as dateFormat from  dctran 
	where  DATE_FORMAT(dctran.FREGDATE,'%Y-%m-%d') between '{$fromdate}' and '{$todate}' AND IFNULL(dctran.FPHOTOPATH,'') != ''";
	$lobj_get_studentInfo = $aobj_context->mobj_db->getAll($query);
	var_dump($query);
	var_dump($lobj_get_studentInfo);die();
	$desDirectry = $aobj_context->main_src."/tmpphotos/".$lobj_get_studentInfo[0]['dateFormat']."/";
	
	$photoDownloadCnt=0;

	foreach($lobj_get_studentInfo as $key=>$value)
	{
		$fURI  ='';
		$photo_path = $value['FPHOTOPATH'];
		
		$file_name=replaceChars(basename($photo_path));
		if(!empty($photo_path) && file_exists($photo_path)) 
		{			
			$fURI = $photo_path;
		}
		
		if(!is_dir($desDirectry))
		{
			mkdir($desDirectry);
			chmod($desDirectry,0777);
		}
	
		$full_file_path= $desDirectry.$file_name;
		//var_dump($full_file_path);die();
		if (file_exists($fURI)) 
		{
			
			$target_file = $full_file_path;//   Path to a local file   
			//var_dump($target_file);die();
			if (file_exists( $target_file )) 
			{
				$ifmodhdr = 'If-Modified-Since: '.date( "r", filemtime( $target_file ) )."\r\n";
			}
			else 
			{
				$ifmodhdr = '';
			}
		   		
			$rc = copy( $fURI, $target_file);

			if($rc) 
			{
				$photoDownloadCnt++;
				if ( fclose( $rc ) )
				{
					unset( $err );		
				}
				else 
				{
					$err = error_get_last();
				}
			}
			else
			{
				$err = error_get_last();
			}
		}	

	} 
	$the_folder = $desDirectry;
	$zip_file_name = "tmpphotos/kus_"."{$lobj_get_studentInfo[0]['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)
	{
		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);
	}
*/
}



?>