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.17.175.167


Current Path : /var/www/html/nehu/src/
Upload File :
Current File : /var/www/html/nehu/src/download_photo_23072020.php

<?php
require_once(_DIR_."/../../aws/aws-autoloader.php");
use Aws\S3\S3Client;
session_start();
function replaceChars($name)
{
	$spl_char = array("*","/","~","!","@","#","$","%","^","&",":",";","?","/","\\","_","-","'"," ","");
	$link_name = strtolower(str_replace($spl_char,"_",$name));
	return str_ireplace("__","_",$link_name);
}


function downloadAllStudentPhotos($aobj_context)
{
	ini_set('memory_limit','300M');
	
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	$college_code = $_SESSION['collcode']; 
	
	$college_from = $aobj_context->mobj_data['college_from'];
	$college_to = $aobj_context->mobj_data['college_to'];
	
	$degree_from = $aobj_context->mobj_data['degree_from'];
	$degree_to = $aobj_context->mobj_data['degree_to'];
	
	$sql_dateFormat = "select CONCAT(DAY(NOW()),MONTH(NOW()),YEAR(NOW()),HOUR(NOW())) as dateFormat,funivcode from control";
	$lobj_dateFormat = $aobj_context->mobj_db->getRow($sql_dateFormat);
	$FUNIVCODE = $lobj_dateFormat['funivcode'];
	$sql_dateFormat = "select CONCAT(DAY(NOW()),MONTH(NOW()),YEAR(NOW()),HOUR(NOW()),SECOND(NOW())) as dateFormat ";
	$lobj_dateFormat = $aobj_context->mobj_db->getRow($sql_dateFormat);

	$get_studentInfo = "SELECT DISTINCT fcollcode, fdegree,fphotopath,faregno FROM studadm 
						WHERE fdegree BETWEEN '{$degree_from}' AND '{$degree_to}'
						AND fcollcode BETWEEN '{$college_from}' AND '{$college_to}' 
						ORDER BY fcollcode,fdegree";
	$lobj_get_studentInfo = $aobj_context->mobj_db->getAll($get_studentInfo);
	//var_dump($get_studentInfo);die();

	$desDirectry = $aobj_context->main_src."/tmpphotos/".$lobj_dateFormat['dateFormat'].'/';

	$desDirectry = $aobj_context->main_src."/tmpphotos/".$degree_code.$lobj_dateFormat['dateFormat'].'/';

	//var_dump($aobj_context->main_src);
	$array = substr($aobj_context->main_src, 0, -7);
	//$desDirectry = $array.'adm/sikkim'."/tmpphotos/".$lobj_dateFormat[dateFormat].'/';
	//var_dump($desDirectry);die();
	$photoDownloadCnt = 0;

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


	foreach($lobj_get_studentInfo as $key=>$value)
	{
		/* 
		$fcollcode = $value['fcollcode'];
		$fdegree = $value['fdegree'];
		$fdegree = strtolower($fdegree);
		//$url = str_replace('student/kusdde','kusdde',$url);	
		$fURI = $array."adm/sikkim/student_photos/".$fcollcode."/".$fdegree;
		//var_dump($fURI);die();
		if(!is_dir($desDirectry))
		{
			mkdir($desDirectry);
			chmod($desDirectry,0777);
		}
		$subdir = $desDirectry.'/'.$fcollcode;
		if(!is_dir($subdir))
		{
			mkdir($subdir);
			chmod($subdir,0777);
		}
		$maindir = $subdir."/".$fdegree;
		if(!is_dir($maindir))
		{
			mkdir($maindir);
			chmod($maindir,0777);
		}
		//var_dump($maindir);die();
		copyfolder("{$fURI}", "{$maindir}"); */
		
// 		$fURI  ='';
// 		$photo_path = $funivcode.'/'.$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);
// 		}
// 		$regno_index = $value['faregno'];
// 		$ext = pathinfo($file_name, PATHINFO_EXTENSION);
// 		$full_file_path= $desDirectry.$regno_index.".".$ext;
// 		$fURI = $funivcode.'/'.$value['fphotopath'];
// 		if (file_exists($fURI)) 
// 		{
// 			$target_file = $full_file_path;//   Path to a local file    
// 			if (file_exists( $target_file )) 
// 			{
// 				$ifmodhdr = 'If-Modified-Since: '.date( "r", filemtime( $target_file ) )."\r\n";
// 			}
// 			else 
// 			{
// 				$ifmodhdr = '';
// 			}
		   		
// 			//$rc = copy( $fURI, $target_file);
// 			var_dump($fURI);
// $rc = $s3->getObject(['Bucket' => STUDENT_PHOTOS_BUCKET, 'Key' => $fURI, 'SaveAs' => $target_file]);
			// if($rc) 
			// {
			// 	$photoDownloadCnt++;
			// 	if ( fclose( $rc ) )
			// 	{
			// 		unset( $err );		
			// 	}
			// 	else 
			// 	{
			// 		$err = error_get_last();
			// 	}
			// }
			// else
			// {
			// 	$err = error_get_last();
			// }


			$fURI  ='';
		$photo_path = $value['fphotopath'];
		
		$file_name=replaceChars(basename($photo_path));
		$fURI = $FUNIVCODE.'/'.$photo_path;
		//var_dump($fURI);
		//die();
		if(!is_dir($desDirectry))
		{
			mkdir($desDirectry);
			chmod($desDirectry,0777);
		}
		$regno_index = $value['faregno'];
		$ext = pathinfo($file_name, PATHINFO_EXTENSION);
		$full_file_path= $desDirectry.$regno_index.".".$ext;

			$target_file = $full_file_path;//   Path to a local file    
			if (file_exists( $target_file )) 
			{
				$ifmodhdr = 'If-Modified-Since: '.date( "r", filemtime( $target_file ) )."\r\n";
			}
			else 
			{
				$ifmodhdr = '';
			}
		   		
			// $rc = copy( $fURI, $target_file);
			$rc = $s3->getObject(['Bucket' => STUDENT_PHOTOS_BUCKET, 'Key' => $fURI, 'SaveAs' => $target_file]);
			// var_dump($rc);
			// var_dump($target_file);
			// die();
			// 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/"."{$lobj_dateFormat[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);
	}

	
	
	/* $the_folder = $desDirectry;
	$zip_file_name = "tmpphotos/"."{$degree_code}{$lobj_dateFormat[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);
	} */

}

function copyfolder($source, $destination)
{
       $directory = opendir($source);
	   
       //Create the copy folder location
       mkdir($destination);
	   
       //Scan through the folder one file at a time
       while(($file = readdir($directory)) != false)
       {
              //Copy each individual file
              copy($source.'/' .$file, $destination.'/'.$file);
       }
	closedir($directory);
	closedir($destination);
} 


function checkphoto($aobj_context)
{
		$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
		$college_from = $aobj_context->mobj_data['college_from'];
		$college_to = $aobj_context->mobj_data['college_to'];
	
		$degree_from = $aobj_context->mobj_data['degree_from'];
		$degree_to = $aobj_context->mobj_data['degree_to'];
		
		$get_studentInfo = "SELECT DISTINCT fcollcode, fdegree FROM studadm 
						WHERE fdegree BETWEEN '{$degree_from}' AND '{$degree_to}'
						AND fcollcode BETWEEN '{$college_from}' AND '{$college_to}' ORDER BY fcollcode,fdegree";
			$lobj_get_studentInfo = $aobj_context->mobj_db->getAll($get_studentInfo);
		if(count($lobj_get_studentInfo) > 0)
		{
			$arr = '';
			echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");
		}
		else
		{
			$arr = '';
			echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"success");
		}
}



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

?>