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
|
<?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"); $pdid = $_POST["pdid"]; $pimgid = $_POST["pimgid"]; $nowdate = date("Y-m-d H:i:s"); //print_r($_POST);
$sql = "SELECT * FROM product_image WHERE pimgid=". $pimgid ." "; $result=mysql_query($sql); $row = mysql_fetch_array($result,MYSQL_ASSOC); if ($_FILES['pimgfile']['name'] <> '' or $_POST['delimage'] > 0 ) { unlink("../images/product/large/".$row{'pimgfile'}); unlink("../images/product/mid/".$row{'pimgfile'}); unlink("../images/product/thumb/".$row{'pimgfile'}); }
$filelimit = 2 * 1048576; //Filelimit in 2MB if ($_FILES['pimgfile']['name'] <> '') { if ($_FILES['pimgfile']['size'] < $filelimit ){
if (($_FILES["pimgfile"]["type"] == "image/gif") || ($_FILES["pimgfile"]["type"] == "image/GIF") || ($_FILES["pimgfile"]["type"] == "image/jpg") || ($_FILES["pimgfile"]["type"] == "image/JPG") || ($_FILES["pimgfile"]["type"] == "image/jpeg") || ($_FILES["pimgfile"]["type"] == "image/JPEG") || ($_FILES["pimgfile"]["type"] == "image/pjpeg") || ($_FILES["pimgfile"]["type"] == "image/PJEG") || ($_FILES["pimgfile"]["type"] == "image/png") || ($_FILES["pimgfile"]["type"] == "image/x-png") || ($_FILES["pimgfile"]["type"] == "image/PNG") || ($_FILES["pimgfile"]["type"] == "image/X-PNG")) { $filename=$_FILES['pimgfile']['name']; preg_match("/\.([^\.]+)$/", $filename, $file_ext); copy ($_FILES['pimgfile']['tmp_name'], "../images/product/large/product_".$pdid."_".$pimgid.".".$file_ext[1]) or die ("Could not copy the file: Product Photo(large)"); $imagelarge = "../images/product/large/product_".$pdid."_".$pimgid.".".$file_ext[1]; createthumb($imagelarge, $imagelarge, 800, 800); copy ($_FILES['pimgfile']['tmp_name'], "../images/product/mid/product_".$pdid."_".$pimgid.".".$file_ext[1]) or die ("Could not copy the file: Project Photo(mid)"); $imagemid = "../images/product/mid/product_".$pdid."_".$pimgid.".".$file_ext[1]; createthumb($imagemid, $imagemid, 180, 180); copy ($_FILES['pimgfile']['tmp_name'], "../images/product/thumb/product_".$pdid."_".$pimgid.".".$file_ext[1]) or die ("Could not copy the file: Product Photo(thumb)"); $imagethumb = "../images/product/thumb/product_".$pdid."_".$pimgid.".".$file_ext[1]; createthumb($imagethumb, $imagethumb, 400, 400); $pimgfile = "product_".$pdid."_".$pimgid.".".$file_ext[1]; $pimgfile = htmlspecialchars($pimgfile,ENT_QUOTES); } } else { // upload error ?> <script language="javascript"> alert("Files must be JPEG, GIF, or PNG and under 2MB in size"); history.back(); </script> <?php exit; }
} else { $pimgfile = ""; }
// Modify $sql = "update product_image set modifyday='$nowdate', cmsloginid='".$_SESSION['cmsloginid']."' "; if ($pimgfile <> '' or $_POST['delimage'] > 0 ) $sql .= ", pimgfile='$pimgfile' "; $sql .= " where pimgid=". $pimgid ." "; mysql_query($sql);
if( mysql_errno() > 0 ){ echo 'Modify Product Detail(Images) Error:<br />'. mysql_error() .'<br />SQL: '. $sql; exit; }
mysql_close($dbh);
header("Location: product_image_index.php?pdid=$pdid&msg=Modify Successful"); ?>
|