-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaveqn.php
68 lines (65 loc) · 1.95 KB
/
saveqn.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
$qnCount = file_get_contents('questions/qnCount.txt');
if($qnCount =='')
{
$qnCount = 0;
}
$curQn = $qnCount + 1;
$a = $_POST['qn'];
$b = $_POST['opn1'];
$c = $_POST['opn2'];
$d = $_POST['opn3'];
$e = $_POST['opn4'];
$f = $_POST['ans'];
$typ = $_POST['typ'];
if($typ == 'txt')
{
mkdir("questions/$curQn/");
file_put_contents("questions/$curQn/QUESTION.txt","$a");
file_put_contents("questions/$curQn/OPTIONA.txt","$b");
file_put_contents("questions/$curQn/OPTIONB.txt","$c");
file_put_contents("questions/$curQn/OPTIONC.txt","$d");
file_put_contents("questions/$curQn/OPTIOND.txt","$e");
file_put_contents("questions/$curQn/ANSWER.txt","$f");
file_put_contents('questions/qnCount.txt',"$curQn");
header('location:addqnform.php');
}
else
{
mkdir("questions/$curQn/");
$allowedExts = array("jpg");
$temp = explode(".", $_FILES["IMGX"]["name"]);
$extension = end($temp);
if ((($_FILES["IMGX"]["type"] == "image/jpeg")
|| ($_FILES["IMGX"]["type"] == "image/jpg"))
&& ($_FILES["IMGX"]["size"] < 8000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["IMGX"]["error"] > 0)
{
echo "Return Code: " . $_FILES["IMGX"]["error"] . "<br>";
rmdir("questions/$curQn/");
}
else
{
move_uploaded_file($_FILES["IMGX"]["tmp_name"],
"questions/$curQn/" . $_FILES["IMGX"]["name"]);
$tempa = "questions/$curQn/" . $_FILES["IMGX"]["name"];
$tempb = "questions/$curQn/QUESTION." . $extension;
rename($tempa,$tempb);
file_put_contents("questions/$curQn/OPTIONA.txt","$b");
file_put_contents("questions/$curQn/OPTIONB.txt","$c");
file_put_contents("questions/$curQn/OPTIONC.txt","$d");
file_put_contents("questions/$curQn/OPTIOND.txt","$e");
file_put_contents("questions/$curQn/ANSWER.txt","$f");
file_put_contents('questions/qnCount.txt',"$curQn");
header('location:addqnform.php');
}
}
else
{
rmdir("questions/$curQn/");
echo "Invalid file ";
}
}
?>