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 include 'config.php';
// Check if the user is logged in
if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1')) { header("Location: login.php"); exit; } require("configure.php"); require("function_resizethumb.php");
$galleryid = htmlspecialchars($_POST["galleryid"],ENT_QUOTES); $nowdate = date("Y-m-d H:i:s"); //print_r($_POST);
// copy image
//check total file size $total_file_size_byte = 0; for($i=0; $i<count($_FILES['galleryfile']['name']); $i++) { $total_file_size_byte = $total_file_size_byte + $_FILES['galleryfile']['size'][$i];
} $total_file_size_MB = $total_file_size_byte / 1024 / 1024;
if($total_file_size_MB > 9.5){ header("Location: gallery_detail_index.php?galleryid=0&msg=Upload file unsuccessfully! Uploaded file size over the maximum size 10MB!"); }else{
for($i=0; $i<count($_FILES['galleryfile']['name']); $i++) { if ($_FILES['galleryfile']['name'][$i] <> '') {
if (($_FILES['galleryfile']["type"][$i] == "image/gif") || ($_FILES['galleryfile']["type"][$i] == "image/GIF") || ($_FILES['galleryfile']["type"][$i] == "image/jpg") || ($_FILES['galleryfile']["type"][$i] == "image/JPG") || ($_FILES['galleryfile']["type"][$i] == "image/jpeg") || ($_FILES['galleryfile']["type"][$i] == "image/JPEG") || ($_FILES['galleryfile']["type"][$i] == "image/pjpeg") || ($_FILES['galleryfile']["type"][$i] == "image/PJEG") || ($_FILES['galleryfile']["type"][$i] == "image/png") || ($_FILES['galleryfile']["type"][$i] == "image/x-png") || ($_FILES['galleryfile']["type"][$i] == "image/PNG") || ($_FILES['galleryfile']["type"][$i] == "image/X-PNG")) {
$sql = "select max(gdetid) as maxid "; $sql .= "from gallery_detail "; $result=mysql_query($sql); $row = mysql_fetch_array($result,MYSQL_ASSOC); $gdetid = $row{maxid}+1;
$sql2 = "select max(gdetsort) as maxidsort from gallery_detail where galleryid = '".$galleryid."'"; $result2=mysql_query($sql2); $row2 = mysql_fetch_array($result2,MYSQL_ASSOC); $gdetsort = $row2{maxidsort}+1;
$filename=$_FILES['galleryfile']['name'][$i]; //preg_match("/\.([^\.]+)$/", $filename, $file_ext);
copy ($_FILES['galleryfile']['tmp_name'][$i], "../images/gallery/large_".$galleryid."_".$gdetid."_".$filename) or die ("Could not copy the file: Project Photo(large)");
$imagelarge = "../images/gallery/large_".$galleryid."_".$gdetid.".".$filename; createthumb($imagelarge, $imagelarge, 800, 800); /* copy ($_FILES['galleryfile']['tmp_name'][$i], "../images/gallery/mid/gallery_".$galleryid."_".$gdetid.".".$filename) or die ("Could not copy the file: Project Photo(mid)");
$imagemid = "../images/gallery/mid/gallery_".$galleryid."_".$gdetid.".".$filename; createthumb($imagemid, $imagemid, 180, 180); */ copy ($_FILES['galleryfile']['tmp_name'][$i], "../images/gallery/thumb_".$galleryid."_".$gdetid."_".$filename) or die ("Could not copy the file: Project Photo(thumb)");
$imagethumb = "../images/gallery/thumb_".$galleryid."_".$gdetid."_".$filename; createthumb($imagethumb, $imagethumb, 200, 200);
$galleryfile[$i] = $galleryid."_".$gdetid."_".$filename; $galleryfile[$i] = htmlspecialchars($galleryfile[$i],ENT_QUOTES);
// Save DB $sql = "insert into gallery_detail (gdetid, galleryid, gdetimage, gdetsort, gdetstatus, createdate,createby, lastupdate, lastupby) values ('$gdetid', '$galleryid', '".$galleryfile[$i]."', '".$gdetsort."', '1', '$nowdate','".$_SESSION['cmsloginid']."', '$nowdate', '".$_SESSION['cmsloginid']."')"; mysql_query($sql); if( mysql_errno() > 0 ){ echo 'Add gallery Detail(Images) Error:<br />'. mysql_error() .'<br />SQL: '. $sql; exit; } //$x++; }else{ // upload error ?> <script language="javascript"> alert("Files must be JPEG, GIF, or PNG and under 10MB in total size"); history.back(); </script> <?php exit; } } else { $galleryfile[$i] = ""; } } } // End copy image
mysql_close($dbh);
header("Location: gallery_detail_index.php?galleryid=$galleryid&msg=Add Successful"); ?>
|