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.147.77.119
<?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()),SECOND(NOW())) as dateFormat ";
$lobj_dateFormat = $aobj_context->mobj_db->getRow($sql_dateFormat);
$get_studentInfo = "SELECT DISTINCT fcollcode, fdegree FROM student
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(count($lobj_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, -5);
//$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."student/jssm/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}");
}
$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();
delTree($the_folder);
}
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 delTree($dir)
{
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file)
{
(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
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);
}
}
}
?>
|