| Current Path : /var/www/html/rkala/submission_portal/ |
| Current File : /var/www/html/rkala/submission_portal/submit.php |
<?php
$user = $_POST['username'];
$password = $_POST['password'];
$assignment = $_POST['assignment'];
$question = $_POST['question'];
$assignment_dir = "codes/Assignment-".$assignment;
$user_dir = $assignment_dir."/".$user;
$target_dir = $user_dir."/".$question."/";
$uploadOk = 1;
$target_file = $target_dir . basename($_FILES["code"]["name"]);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$true = chk_user($user, $password);
if(!$true) {
die("Login Failed");
}
if(isset($_POST["submit"])) {
// Check if assignment directory already exists
if(!file_exists($assignment_dir)) {
mkdir($assignment_dir, 0777);
}
if(!file_exists($user_dir)) {
mkdir($user_dir, 0777);
}
// Check if target file already exists
if (!file_exists($target_dir)) {
mkdir($target_dir, 0777);
}
// Allow certain file formats
if($imageFileType != "java") {
echo "Sorry, only JAVA files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["code"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["code"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
else {
echo "POST request required";
}
function chk_user( $uid, $pwd ) {
if ($pwd) {
$ds = ldap_connect("172.31.1.42");
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;
}
}
?>