| Current Path : /var/www/html/rkala/portal/ |
| Current File : /var/www/html/rkala/portal/download.php |
<?php
$user = $_POST['username'];
$password = $_POST['password'];
$assignment = $_POST['assignment'];
$true = chk_user($user, $password) && ($user == "rkala" || $user == "icm2014501" || $user == "pis2016001");
if(!$true) {
die("Login Failed");
}
$assignment_dir = "codes/Assignment-".$assignment;
$target_dir = $assignment_dir;
$uploadOk = 1;
$dir = $target_dir;
$zip_file = 'zips/Assignment-'.$assignment.'.zip';
// Get real path for our folder
$rootPath = realpath($dir);
// Initialize archive object
$zip = new ZipArchive();
$zip->open($zip_file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
// Skip directories (they would be added automatically)
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
// Add current file to archive
$zip->addFile($filePath, $relativePath);
}
}
// Zip archive will be created only after closing object
$zip->close();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($zip_file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($zip_file));
readfile($zip_file);
function chk_user( $uid, $pwd ) {
if ($pwd) {
$ds = ldap_connect("172.31.1.41");
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$a = ldap_search($ds, "dc=iiita,dc=ac,dc=in", "uid=".$uid );
$b = ldap_get_entries( $ds, $a );
$dn = $b[0]["dn"];
$ldapbind=@ldap_bind($ds, $dn, $pwd);
if ($ldapbind) {
return 1;
} else {
return 0;
}
ldap_close($ds);
} else {
return 0;
}
}
?>