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
|
<?php include 'config.php';
// Check if the user is logged in
if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1')) { header("Location: login.php"); exit; }
require_once("function_cropimg.php"); require_once("mime_type_lib.php");
$nowdate = date("Y-m-d H:i:s");
// Sort $sql1 = "select max(slideid) as maxid from slideshow"; if (!($sth1 = $dbh->prepare($sql1))) { throw new Exception('[' . $sth1->errorCode() . ']: ' . print_r($sth1->errorInfo())); }
if (!$sth1->execute()) { throw new Exception('[' . $sth1->errorCode() . ']: ' . print_r($sth1->errorInfo())); }
$row = $sth1->fetch(PDO::FETCH_ASSOC); $slideid = $row{"maxid"} + 1;
$sql1 = "select max(sort) as maxid from slideshow where deleted = 0";
if (!($sth1 = $dbh->prepare($sql1))) { throw new Exception('[' . $sth1->errorCode() . ']: ' . print_r($sth1->errorInfo())); }
if (!$sth1->execute()) { throw new Exception('[' . $sth1->errorCode() . ']: ' . print_r($sth1->errorInfo())); }
$row = $sth1->fetch(PDO::FETCH_ASSOC); $sort = $row{"maxid"} + 1;
foreach ($arraylangcode as $langcode => $langname) { $slidelink[$langcode] = "";
// Upload File
if ($_FILES["slideimg_" . $langcode]['name'] <> '') {
//check if image type is valid or not $mime = get_file_mime_type($_FILES["slideimg_" . $langcode]['name']);
if ((!strpos($mime,"image/gif") || !strpos($mime,"image/jpeg") || !strpos($mime,"image/png"))) {
$filename = $_FILES["slideimg_" . $langcode]['name']; preg_match("/\.([^\.]+)$/", $filename, $file_ext); $newfilename = random_string() . "_slideid_" . $slideid . "." . $file_ext[1]; // default length 8
move_uploaded_file($_FILES["slideimg_" . $langcode]['tmp_name'], "../images/slideshow/" . $newfilename) or die ("Could not copy the file");
//$slideimg_path = "../images/slideshow/".$newfilename;
//createthumb($slideimg_path, $slideimg_path, 680, 350);
$slideimg[$langcode] = $newfilename;
} else { echo '<script language="javascript"> alert("圖片格式必須是 JPEG, GIF, or PNG"); history.back(); </script>';
exit; }
} else { $slideimg[$langcode] = ""; }
}
$sql = "insert into slideshow (slideid, sort, slidelink_en, slideimg_en,slidelink_tc, slideimg_tc, createdate, createby, lastupdate, lastupby) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$parameters = array($slideid, $sort, $slidelink["en"], $slideimg["en"],$slidelink["tc"], $slideimg["tc"], $nowdate, $_SESSION['cmsloginid'], $nowdate, $_SESSION['cmsloginid']);
if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
if (!$sth->execute($parameters)) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
$dbh = null;
header("Location: slideshow_index.php?msg=Add Successfully");
|