예제 #1
0
 function save($p, $vars)
 {
     //print_r($p); return;
     //print_r($vars); return;
     //$user_id = $_SESSION['USERID'];
     //$from_ip = getenv ("REMOTE_ADDR");
     $c = new Sale($this->db_conn);
     $c->getData($vars['id']);
     $old_photo = $c->photo;
     $c->name_cht = $vars['name_cht'];
     $c->name_eng = $vars['name_eng'];
     $c->brief_cht = $vars['brief_cht'];
     $c->brief_eng = $vars['brief_eng'];
     $c->desp_cht = $vars['desp_cht'];
     $c->desp_eng = $vars['desp_eng'];
     $c->vw_cht = $vars['vw_cht'];
     $c->vw_eng = $vars['vw_eng'];
     $c->hotspot_cht = $vars['hotspot_cht'];
     $c->hotspot_eng = $vars['hotspot_eng'];
     $c->seq = $vars['seq'];
     $c->code = $vars['code'];
     //$this->gotoURL("user.php?action=list");
     $c->update();
     //上傳
     $uploaddir = HTML_ROOT_PATH . "photo/sale/" . $c->id . "/";
     if ($vars['photo_del'] == "Y") {
         $old_logo = "";
         $deletefile = $uploaddir . $old_logo;
         //舊圖圖檔路徑
         if (file_exists($deletefile)) {
             //檢查文件OR目錄是否存在
             unlink($deletefile);
             //刪除文件
             $c->photo = "";
             //資料庫檔案名清空
         }
     }
     if ($vars['photo']['name'] != "") {
         if (!is_dir($uploaddir)) {
             mkdir($uploaddir, 0777);
         }
         $pos = strrpos($vars['photo']['name'], ".");
         //查詢"."在$vars['logo']['name']最後一次出現位置 (取得檔名長度)
         $extension = strtolower(substr($vars['photo']['name'], $pos + 1));
         //返回$vars['logo']['name']從(檔名長度)加.開始  (取得檔案類型)
         $dst_file = "logo_" . $c->id . "." . $extension;
         //會員ID的圖檔名
         $dst_file_path = $uploaddir . $dst_file;
         //加上圖檔路徑目錄
         $photoname = $dst_file;
         //會員ID圖檔名塞進$photoname變數
         if ($old_logo != "") {
             $deletefile = $uploaddir . $old_photo;
             if (file_exists($deletefile)) {
                 unlink($deletefile);
                 $c->logo = "";
             }
         }
         $src_file = $vars['photo']['tmp_name'];
         $im = @imagecreatefromjpeg($vars['photo']['tmp_name']);
         //php從jpeg文件OR URL新建一圖象
         $imx = imagesx($im);
         //取圖寬
         $imy = imagesy($im);
         //取圖高
         $new_w = 400;
         $new_h = 400;
         if ($imx > $new_w || $imy > $new_h) {
             // 縮圖
             $src_file = resize_image($vars['photo']['tmp_name'], $src_file, $new_w, $new_h);
         }
         $photouploadfile = $uploaddir . $dst_file;
         if (copy($src_file, $photouploadfile)) {
             //logo圖檔複製到指定目錄
             $c->photo = $photoname;
             //print_r($photoname);                      //資料庫logo欄位寫進 會員ID的圖檔名
         } else {
             echo $photouploadfile . "<br>";
             echo "Possible Photo file upload attack!\n";
         }
     }
     $c->update();
     $this->gotoURL("sale.php?action=list");
     //$this->gotoURL("sale.php?action=show&id=".$c->id);
     //$this->browse($p);
 }