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.217.104.36
<?php
require_once(_DIR_."/../../aws/aws-autoloader.php");
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
session_start();
ini_set('max_execution_time', '300');
ini_set('memory_limit','1G');
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 s.fdegree,s.fregno,s.FPHOTOPATH, c.funivcode from student s , control c
where s.fdegree = '{$degree_code}'
and s.fregno between '{$RegNo_start}' and '{$RegNo_end}' AND IFNULL(s.FPHOTOPATH,'') != '' ORDER BY s.fregno ";
$lobj_get_studentInfo = $aobj_context->mobj_db->getAll($get_studentInfo);
$FUNIVCODE = $lobj_get_studentInfo[0]['funivcode'];
$desDirectry = $aobj_context->main_src."/tmpphotos/".$degree_code.$lobj_dateFormat['dateFormat'].'/';
$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)
{
$fURI ='';
$photo_path = $value['FPHOTOPATH'];
$file_name=replaceChars(basename($photo_path));
$fURI = $FUNIVCODE.'/'.$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;
$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);
try
{
$rc = $s3->getObject(['Bucket' => STUDENT_PHOTOS_BUCKET, 'Key' => $fURI, 'SaveAs' => $target_file]);
} catch(S3Exception $e) {
$excepted = true;
// Assert::assertEquals('NoSuchKey', $e->getAwsErrorCode());
} finally {
// Assert::assertTrue($excepted);
}
// 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;
// $command = "zip -r ".$zip_file_name." tmpphotos/".$degree_code.$lobj_dateFormat['dateFormat'];
// $res = exec($command);
$za = new FlxZipArchive;
// $za = new ZipArchive();
$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)
{
$command = "rm -r $desDirectry";
$res = exec($command);
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);
}
}
}
?>
|