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
|
<?php include_once('../../check_login.php');
$for_table = $_POST["for_table"]; $for_refid = (int)$_POST["for_refid"];
//insert db error_reporting(E_ALL); ini_set('display_errors', 1);
foreach ($arraylangcode as $langcode => $langname) { if (!empty($_POST["filename_" . $langcode])) { require_once("../../function_cropimg.php"); require_once("../../mime_type_lib.php");
//contain file title and file id $filename = $_POST["filename_" . $langcode]; //eg: this is product image
foreach ($filename as $key => $this_file) {
//image resize, insert into db $sql = "select max(refid) as maxid from upload_file "; if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
if (!$sth->execute()) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
$row = $sth->fetch(PDO::FETCH_ASSOC);
$refid = $row{"maxid"} + 1;
//get file name in temp table $sql = "select * from temp_file where file_id = ?"; $parameters = array($this_file["file_id"]); 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())); } $file_info = $sth->fetch(PDO::FETCH_ASSOC); //you can get uploader id from file_info
$file_path = "plupload/uploads/" . $file_info{"file_name"}; $file_ext = pathinfo($file_path);
$img_name = "event_photo_" .random_string(10). "." . $file_ext['extension'];
//copy file to right folder copy($file_path, "../../../file/event_photo/" . $img_name) or die ("Could not copy the file"); unlink($file_path);
// Save DB $sql = "insert into upload_file (refid, for_refid, for_table, file_name, langcode, createdate, createby, lastupdate, lastupby) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"; $parameters = array($refid, $for_refid, $for_table, $img_name, $file_info["langcode"], $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())); }
//deleted the original file unlink($file_path);
} } } $dbh = null;
header("Location: upload_file_index.php?for_table=" . $for_table . "&for_refid=" . $for_refid . "&msg=Add Successfully");
?>
|