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
|
<?php require_once("check_login.php"); require_once("function_cropimg.php"); require_once("mime_type_lib.php");
$productid = $_POST["productid"]; //one of the editor name, it contain file title and file id $proimage = $_POST["proimage"]; //eg: this is product image
foreach ($proimage as $key => $this_file) {
//image resize, insert into db $sql = "select max(proimgid) as maxid from pro_image "; $row = bind_pdo($sql, NULL, "selectone");
$proimgid = $row{"maxid"} + 1;
$sql = "select max(sort) as maxsort from pro_image where productid=? and deleted = ? "; $parameters = array($productid, "0"); $row2 = bind_pdo($sql, $parameters, "selectone");
$max_sort = $row2{"maxsort"} + 1;
//get file name in temp table $sql = "select * from temp_file where file_id = ?"; $parameters = array($this_file["file_id"]); $file_info = bind_pdo($sql, $parameters, "selectone"); //you can get uploader id from file_info
$file_path = "plupload/uploads/" . $file_info{"file_name"}; $file_ext = pathinfo($file_path);
//copy file to right folder copy($file_path, "../images/product_images/large/proimgid_" . $proimgid . "." . $file_ext['extension']) or die ("Could not copy the file");
copy($file_path, "../images/product_images/thumb/proimgid_" . $proimgid . "." . $file_ext['extension']) or die ("Could not copy the file");
//resize file (optional) $fileimg = "../images/product_images/large/proimgid_" . $proimgid . "." . $file_ext['extension']; createthumb($fileimg, $fileimg, 800, 600);
$fileimg = "../images/product_images/thumb/proimgid_" . $proimgid . "." . $file_ext['extension']; createthumb($fileimg, $fileimg, 400, 300);
$img_name = "proimgid_" . $proimgid . "." . $file_ext['extension'];
// Save DB $sql = "insert into pro_image (proimgid, productid, photo, photo_title, sort, createdate, createby, lastupdate, lastupby, deleted) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$parameters = array($proimgid, $productid, $img_name, $this_file["file_title"], $max_sort, $nowdate, $_SESSION['cmsloginid'], $nowdate, $_SESSION['cmsloginid'], "0");
bind_pdo($sql, $parameters);
//deleted the original file unlink($file_path); }
header("Location: product_detail_index.php");
|