forked from storm95/nishiAgarwal.in
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploadPhoto.php
141 lines (128 loc) · 3.78 KB
/
uploadPhoto.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
$defineVariablesPhp = "defineVariables.php";
require $defineVariablesPhp;
require $dbConnectPhp;
require $queryFunctionsPhp;
require $phpFunctionsPhp;
?>
<?php
$msg = NULL;
if(isset($_POST[$dbChangeType]) && !empty($_POST[$dbChangeType]))
{
$getDbChangeType = mysql_real_escape_string($_POST[$dbChangeType]);
if($getDbChangeType == $dbChangeTypeDelete)
{
//Delete Photo
if(isset($_POST[$colName]) && !empty($_POST[$colName]) )
{
$getColName = $_POST[$colName];
$query = 'DELETE FROM `'.$dbName.'`.`'.$photoTableName.'` WHERE `'.$colName.'`="'.$getColName.'"';
if(@mysql_query($query))
{
$msg = $getColName." is Deleted";
}
else
{
$msg = "Error in Deletion. Error : ".mysql_error()." query : ".$query;
}
}
else
{
$msg = "You didnot fill the Photo Name";
}
}
elseif($getDbChangeType == $dbChangeTypeAdd)
{
if((isset($_FILES[$photoFile]) && $_FILES[$photoFile]['error'] != UPLOAD_ERR_NO_FILE)
&&(isset($_POST[$colName]) && !empty($_POST[$colName]))
&&(isset($_POST[$colDescription]))
&&(isset($_POST[$colSize]))
&&(isset($_POST[$colRank]))
)
{
$getColName = $_POST[$colName];
$getColDescription = $_POST[$colDescription];
$getColSize = $_POST[$colSize];
$getColRank = $_POST[$colRank];
$info = pathinfo($_FILES[$photoFile]['name']);
$ext = $info['extension']; // get the extension of the file
$colPhotoFileNameVal = $getColName.".".$ext;
$target = $photoDir.'/'.$colPhotoFileNameVal;
if( is_writable($photoDir) && move_uploaded_file( $_FILES[$photoFile]['tmp_name'], $target))
{
echo 'File Uploaded';
}
else
{
echo 'Not uploaded';
}
$query= 'INSERT INTO `'.$dbName.'`.`'.$photoTableName.'` (
`'.$colName.'` ,
`'.$colDescription.'` ,
`'.$colSize.'`,
`'.$colRank.'`,
`'.$colPhotoFileName.'`
)
VALUES (
"'.$getColName.'", "'.$getColDescription.'", "'.$getColSize.'", "'.$getColRank.'", "'.$colPhotoFileNameVal.'"
)';
if(@mysql_query($query))
{
$msg = $getColName." successfully added.";
}
else
{
$msg = "Error in Adding Photo. Error : ".mysql_error();
}
}
else
{
$msg = "Error. You didnot fill all the Fields";
}
}
}
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=divice-width, initial-scale=1.0">
<title>Nishi Agarwal</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/customIndex.css">
</head>
<body>
<div class="container">
<section>
<div class="row">
<h2><?php echo $msg; ?></h2>
</div>
</section>
<section>
<div class="row">
<p> For Add : You have to fill in all the fields</p>
<p> For Delete : You have to fill only the Photo Name</p>
</div>
</section>
<section>
<div class="row">
<form action="uploadPhoto.php" method="POST" enctype="multipart/form-data">
<input type="radio" name=<?php echo '"'.$dbChangeType.'"'; ?> value=<?php echo '"'.$dbChangeTypeAdd.'"'; ?> checked> Add<br>
<input type="radio" name=<?php echo '"'.$dbChangeType.'"'; ?> value=<?php echo '"'.$dbChangeTypeDelete.'"'; ?> > Delete<br>
<br>
<input name=<?php echo '"'.$photoFile.'"'; ?> type="file"/>
<br>
<input name=<?php echo '"'.$colName.'"'; ?> placeholder="Photo Name"/>
<br>
<textarea name=<?php echo '"'.$colDescription.'"'; ?> placeholder="Description"></textarea>
<br>
<input name=<?php echo '"'.$colSize.'"'; ?> placeholder="Size"/>
<br>
<input name=<?php echo '"'.$colRank.'"'; ?> placeholder="Rank"/>
<br>
<input type="submit" value="Submit"/>
</form>
</div>
</section>
</div>
</body>
</html>