-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviewphotos.php
127 lines (121 loc) · 3.7 KB
/
viewphotos.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
<?php
include("header.php");
include("connection.php");
?>
<script type="text/JavaScript">
function confirmDelete(){
var agree=confirm("Are you sure you want to delete this image?");
if (agree)
return true;
else
return false ;
}
</script>
<?php
if(isset($_GET["phid"]))
{
mysqli_query($con,"Delete from upload_data where slnum='$_GET[phid]'");
if(mysqli_affected_rows($con) == 1)
{
$recc = 1;
}
}
if(isset($_FILES['files'])){
$errors= array();
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$file_name = $key.$_FILES['files']['name'][$key];
$file_size =$_FILES['files']['size'][$key];
$file_tmp =$_FILES['files']['tmp_name'][$key];
$file_type=$_FILES['files']['type'][$key];
if($file_size > 2097152){
$errors[]='File size must be less than 2 MB';
}
$query="INSERT into upload_data (album_id ,file_name,file_size,fle_type) VALUES('$_POST[albumid]','$file_name','$file_size','$file_type'); ";
$desired_dir="user_data";
if(empty($errors)==true){
if(is_dir($desired_dir)==false){
mkdir("$desired_dir", 0700); // Create directory if it does not exist
}
if(is_dir("$desired_dir/".$file_name)==false){
move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
}else{ // rename the file if another one exist
$new_dir="$desired_dir/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
mysqli_query($con,$query);
}else{
print_r($errors);
}
}
if(empty($error)){
$success = "Photos uploaded successfully";
}
}
$result5 = mysqli_query($con,"SELECT * FROM gallery where album_id ='$_GET[albumid]'");
while($row5 = mysqli_fetch_array($result5))
{
$albumname = $row5[album_name];
}
$result = mysqli_query($con,"SELECT * FROM upload_data WHERE album_id ='$_GET[albumid]'");
?>
<div id="main">
<div id="content" class="left">
<div class="highlight">
<h3>View photos</h3>
<p> <?php echo $success; ?></p>
<form action="" method="POST" enctype="multipart/form-data">
Upload photos
<input type="file" name="files[]" multiple/>
<input type="hidden" name="albumid" value="<?php echo $_GET[albumid];?>" />
<input type="submit"/>
</form>
<br />
<table width="546" border="1">
<tr>
<th height="51" colspan="4" scope="col"> Album Name
: <?php echo $albumname ;
if($recc == 1)
{
echo "<br>Image deleted successfully...";
}
?>
</th>
</tr>
<tr>
<th width="106" height="51" scope="col">Image</th>
<th width="112" scope="col">File Size</th>
<th width="185" scope="col">File Type</th>
<th width="115" scope="col">Delete</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td> <img src='user_data/$row[file_name]' width='100' height='100' > <img></td>";
echo "<td> ".$row[file_size]/1024 . " MB</td>";
echo "<td> $row[fle_type]</td>";
echo "<td> <a href='viewphotos.php?phid=$row[slnum]&albumid=$_GET[albumid]' onClick='return confirmDelete();'> Delete</td>";
echo "</tr>";
}
?>
</table>
</div>
<div class="projects">
<div class="item"></div>
<div class="item">
<div class="cl"> </div>
</div>
</div>
</div>
<?php
include("sidebar.php");
?>
<div class="cl"> </div>
</div>
<div class="shadow-l"></div>
<div class="shadow-r"></div>
<div class="shadow-b"></div>
</div>
<?php
include("footer.php");
?>