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.128.94.112
<?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 fdegree,fregno,FPHOTOPATH from student
where fdegree = '{$degree_code}'
and fregno between '{$RegNo_start}' and '{$RegNo_end}' AND IFNULL(FPHOTOPATH,'') != '' ORDER BY fregno ";
$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 = '';
}
$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);
}
}
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);
}
}
}
?>
|