/var/www/(Del)standraise.com/admin/productimagemodify.php


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
<?php require("configure.php"); ?>
<?
$productcatid        
$_POST["productcatid"];
$productimageid        $_POST["productimageid"];
//$productname        = $_POST["productname"];
$productname        htmlspecialchars($_POST["productname"],ENT_QUOTES);
//$productmodel        = $_POST["productmodel"];
$productmodel        htmlspecialchars($_POST["productmodel"],ENT_QUOTES);
//$productdesc        = $_POST["productdesc"];
$productdesc        preg_replace("/'/","\'",$_POST["productdesc"]);
$sortbyimage        $_POST["sortbyimage"];

if (
$_FILES['image']['name'] <> '')
{
    
move_uploaded_file ($_FILES['image']['tmp_name'], "product/".$productimageid.$_FILES['image']['name']) 
        or die (
"Could not copy, File Size Max.2M and change the filename to all english."); 
    
$image $productimageid.$_FILES['image']['name'];
    
    
$images "product/".$productimageid.$_FILES['image']['name'];
    
$smallproduct "smallproduct/".$productimageid.$_FILES['image']['name'];
    
$slideshow "slideshow/".$productimageid.$_FILES['image']['name'];
    
createthumb($images$images600600);
    
createthumb($images$smallproduct200200);
    
createthumb($images$slideshow200200);
}
else
{
    
$image "";
}

function 
createthumb($name,$filename,$new_w,$new_h)
    {
    
$system=explode('.',$name);
    if (
preg_match('/jpg|jpeg|JPG|JPEG/',$system[1])){
        
$src_img=imagecreatefromjpeg($name);
    }
    if (
preg_match('/png/',$system[1])){
        
$src_img=imagecreatefrompng($name);
    }

    
$old_x=imageSX($src_img);
    
$old_y=imageSY($src_img);
    if (
$old_x $old_y) {
        
$thumb_w=$new_w;
        
$thumb_h=$old_y*($new_h/$old_x);
    }
    if (
$old_x $old_y) {
        
$thumb_w=$old_x*($new_w/$old_y);
        
$thumb_h=$new_h;
    }
    if (
$old_x == $old_y) {
        
$thumb_w=$new_w;
        
$thumb_h=$new_h;
    }

    
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
    
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 


    if (
preg_match("/png/",$system[1]))
    {
        
imagepng($dst_img,$filename); 
    } else {
        
imagejpeg($dst_img,$filename); 
    }
    
imagedestroy($dst_img); 
    
imagedestroy($src_img); 
}

$sql "update productimage set productimageid='$productimageid', productname='$productname', productmodel='$productmodel', productdesc='$productdesc', sortbyimage='$sortbyimage' ";
if (
$image <> '')
    
$sql .= ", image='$image' ";
$sql .= " where productimageid="$productimageid ." ";

//echo $sql;
mysql_query($sql);
mysql_close($dbh);

header("Location: productcatindex.php?pid=$productcatid&msg=Modify Successful");



?>