-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
executable file
·106 lines (78 loc) · 2.79 KB
/
upload.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
session_start();
if(isset($_SESSION['uname']))
echo "current session: " . $_SESSION['uname'];
else
{
echo "not logged in";
$_SESSION['uname']="guest";
}
require_once 'dbconfig/config.php';
date_default_timezone_set("Asia/Kolkata");
?>
<?php
/*if(isset($_POST ["upload"]))
{
echo "fdsfdf";
}*/
if(isset($_POST ["lout"]))
{
session_destroy();
header('location:index.php');
}
?>
<html>
<head><title>Upload a File</title>
<link rel="stylesheet" href="d.css">
</head>
<body>
<form action='' method='POST' enctype="multipart/form-data" >
<center> <b> Financial Year</b> <input type="number" name="year" min="1996" max="2999" ><br><br>
<input type="file" align="center" class="ab" align="center" name="fileToUpload" id="fileToUpload"><br><br>
<input type="submit" class="abc" value="Upload pdf" name="submit">
<a href="view.php" title="View pdf"><input type="button" class="abc" name="View" value="View Previous"></a><br><br>
<button name="lout">Log out</button> </center>
</form>
<?php
$user = $_SESSION['uname'];
$year = $_POST['year'];
$target_Path = "pdf/";
//$target_Path = $target_Path.basename( $_FILES['fileToUpload']['name'] );
$info = pathinfo($_FILES['fileToUpload']['name']);
$ext = $info['extension']; // get the extension of the file
if ($ext!=='pdf' && strlen($ext)>1)
echo "<script>alert('error!!not in pdf format');</script>";
else{
$newname = $_SESSION['uname'].'_'.$year.'_'.date("his"). '.' .$ext;
//$newname = "rs.".$ext;
$target = $target_Path.$newname;
$tmpFilePath = $_FILES['fileToUpload']['tmp_name'];
$moved=move_uploaded_file($tmpFilePath, $target);
if ($moved){
echo "<script>alert('File Uploaded Successfully');</script>";
} else {
?><script>alert('Upload only pdf file:)');</script><?php
}
}
// echo "$year";
if($year>1996)
{
$table = 'itax';
$sql1 = "ALTER TABLE $table ADD data$year VARCHAR( 255 ) NOT NULL";
$query_run1= mysqli_query($con,$sql1);
$sql2 = "UPDATE $table SET data$year = '$target' WHERE USERNAME = '$user'";
$query_run2= mysqli_query($con,$sql2);
$col='data$year'; //to use in view page to retrieve the document
//echo "hello";
}
//move_uploaded_file( $_FILES['fileToUpload']['tmp_name'], $target_Path );
/* $sql = "SHOW COLUMNS FROM '$table'";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result)){
echo $row['Field']."<br>";
}
*/
mysqli_close($con);
?>
</body>
</html>