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


Current Path : /proc/thread-self/root/var/www/html/guk_old/src/
Upload File :
Current File : //proc/thread-self/root/var/www/html/guk_old/src/download_photo22.php

<?php
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 ";
	$lobj_dateFormat = $aobj_context->mobj_db->getRow($sql_dateFormat);
	
	$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,fregno FROM student 
						WHERE fregno BETWEEN '{$degree_from}' AND '{$degree_to}'
						AND fcollcode BETWEEN '{$college_from}' AND '{$college_to}' 
						ORDER BY fcollcode,fdegree";
						//var_dump($get_studentInfo);die();
	$lobj_get_studentInfo = $aobj_context->mobj_db->getAll($get_studentInfo);
	//var_dump($get_studentInfo);die();

	$desDirectry = $aobj_context->main_src."/tmpphotos/".$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;

	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 = $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['fregno'];
		$ext = pathinfo($file_name, PATHINFO_EXTENSION);
		$full_file_path= $desDirectry.$regno_index.".".$ext;
		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);

			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/"."{$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);
	}

	
	
	/* $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,fphotopath,fregno FROM studnet 
						WHERE fregno 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);
		}
	} 
}

?>