######################################## # 更新記錄 ######################################## function op_update($sn="") { global $mysqli,$TBL; if(!$sn)redirect_header("index.php",3000,"更新記錄錯誤!!"); #資料過濾 $_POST['sn'] = intval($_POST['sn']); $_POST['title'] = $mysqli->real_escape_string($_POST['title']); $_POST['enable'] = intval($_POST['enable']); $_POST['sort'] = intval($_POST['sort']); $_POST['kind'] = intval($_POST['kind']); $_POST['date'] = $mysqli->real_escape_string($_POST['date']); $_POST['date'] = strtotime($_POST['date']);//將日期轉成時間戳記 $_POST['price'] = intval($_POST['price']); $_POST['summary'] = $mysqli->real_escape_string($_POST['summary']); $_POST['content'] = $mysqli->real_escape_string($_POST['content']); $sql = "update `{$TBL['name']}` set `title` = '{$_POST['title']}' , `enable` = '{$_POST['enable']}', `sort` = '{$_POST['sort']}', `kind` = '{$_POST['kind']}', `date` = '{$_POST['date']}', `price` = '{$_POST['price']}', `summary` = '{$_POST['summary']}', `content` = '{$_POST['content']}' where sn='{$_POST['sn']}'"; $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate)); /* $_FILES['file']['name']:上傳檔案原始名稱。 $_FILES['file']['type']:檔案的 MIME 類型,例如“image/gif”。 $_FILES['file']['size']:已上傳檔案的大小,單位為bytes。 $_FILES['file']['tmp_name']:檔案被上傳後的臨時檔案名。 $_FILES['file']['error']:和該檔案上傳相關的錯誤代碼。 */ if($_FILES['file'] and !$_FILES['file']['error']) { #刪除舊檔(資料表、實體檔案) $col_name="prod";//商品圖的關鍵字 prod delete_file_name($sn,$col_name); #----------------------- //$col_name=$TBL['kind'];//輪播圖的關鍵字 slider_home $col_sn=$sn;//相關流水號 $sort=1;//排序 $ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);//取得副檔名 $ext = strtolower($ext); //轉小寫 $sub_dir="/prod";//儲存位置 $file_name="prod_".$col_sn."_".$sort.".".$ext;//檔名 if($ext == "png" or $ext == "gif" or $ext == "jpg" or $ext == "jpeg" or $ext == "jpe") { $kind="img"; }else { $kind="file"; } #寫入資料表 show_files $sql = "insert into `show_files` (`col_name`, `col_sn`, `sort`, `kind`,`file_name`,`file_type`,`file_size`,`description`,`sub_dir`) VALUES ('{$col_name}', '{$col_sn}', '{$sort}', '{$kind}', '{$file_name}', '{$_FILES['file']['type']}','{$_FILES['file']['size']}', '{$_POST['title']}', '{$sub_dir}')"; $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate)); $new_file= WEB_PATH."/uploads".$sub_dir."/".$file_name; #移動檔案 move_uploaded_file($_FILES['file']['tmp_name'] , $new_file); } return $sn; }