思路:使用from標籤,設置爲enctype="multipart/form-data"//傳遞數據改成二進制以便圖片傳遞php
使用if ($_POST)進行判斷。有詳細備註,若有疑問能夠留言html
HTML部分(刪除了一些,看看就好)sql
<form action="{$MOD[linkurl]}event.php" method="post" enctype="multipart/form-data"> <div class="zw"> <table> <tr class="fl"> <td><i>*</i>企業名稱:</td> <td><input type="text" name="company" placeholder="請輸入完整企業名稱" value="{$company}"></td> </tr> <tr class="fl"> <td><i>*</i>企業logo:</td> <td><input type="file" name="logo" value="上傳圖片"></td> </tr> <tr class="fl"> <td><i>*</i>企業簡介:</td> <td> <textarea name="introduce" placeholder="請在這裏輸入3000字之內企業介紹">{$introduce}</textarea> </td> </tr> <tr class="fl"> <td class=""><i>*</i>產 品 一 :</td> <td class="sell01"> <input type="text" class="sell" name="sellname" placeholder="產品名稱" value="{$sellname}"> </td> <td class="sell01"> <input type="text" class="sell" name="sellmodel" placeholder="產品型號" value="{$sellmodel}"> </td> <td class="sell01 "> <input type="file" name="sellphoto" class="sell2" value="{$sellphoto}"> </td> </tr> <tr class="fl"> <td></td> <td><textarea placeholder="請在這裏輸入1000字之內產品說明(名稱,型號,圖片,說明缺一不可。產品一爲必填)" name="sellintro">{$sellintro}</textarea></td> </tr> </table> </div> <div> <input class="sub" type="submit" value="提交報名" onclick="chick();" /> </div> </form>
php邏輯部分服務器
if ($_POST) { //限制ip報名次數 $A = $db->get_one("SELECT COUNT(*) AS num FROM `{$DT_PRE}event2017` WHERE `ipadd`='$reIP'"); if ( $A['num']>3) { echo "<script>alert('限制報名三次,若有須要請聯繫業務表明。')</script>"; $chick = 0; } //分類選擇 if ($typeid == 0) { echo "<script>alert('請選擇分類')</script>"; $chick = 0; }else{ if (isnum($typeid)) { $sqlv = "'".$typeid."',"; $sqlk = "typeid,"; }else{ echo "<script>alert('分類參數錯誤,請重試!')</script>"; $chick = 0; } } //企業名稱 if ($company == '') { echo "<script>alert('請輸入公司名稱')</script>"; $chick = 0; }else{ if (ischina($company)) { $company = htmlspecialchars($company); $sqlv .= "'".$company."',"; $sqlk .= "company,"; }else{ echo "<script>alert('須要填入中文公司名稱')</script>"; $chick = 0; } } //聯繫人 if ($contacts == '') { echo "<script>alert('請輸入聯繫人名稱')</script>"; $chick = 0; }else{ if (isnum($contacts) == false) { $contacts = htmlspecialchars($contacts); $sqlv .= "'".$contacts."',"; $sqlk .= "contacts,"; }else{ echo "<script>alert('聯繫人名稱只能使用中文及英文')</script>"; $chick = 0; } } //電話 if ($tel == '') { echo "<script>alert('請輸入聯繫電話')</script>"; $chick = 0; }else{ if (preg_match('#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#', $tel)) { $tel = htmlspecialchars($tel); $sqlv .= "'".$tel."',"; $sqlk .= "tel,"; }else{ echo "<script>alert('請輸入正確的11位手機號碼')</script>"; $chick = 0; } } //企業介紹 if ($introduce == '') { echo "<script>alert('請填寫企業介紹')</script>"; $chick = 0; }else{ if (ischina($introduce)) { $introduce = htmlspecialchars($introduce); $sqlv .= "'".$introduce."',"; $sqlk .= "introduce,"; }else{ echo "<script>alert('須要填入中文公司介紹')</script>"; $chick = 0; } } //第一條產品 if ($sellname == '' || $sellmodel == '' ||$sellintro == '' ||$_FILES["sellphoto"]["name"] == '') { echo "<script>alert('請務必填寫至少一個產品的完整信息')</script>"; $chick = 0; }else{ $sellname = htmlspecialchars($sellname); $sellmodel = htmlspecialchars($sellmodel); $sellintro = htmlspecialchars($sellintro); $sellphoto1 = "sellphoto"; $addpt = imageUP($sellphoto1); $sqlv .= "'".$sellname."','".$sellmodel."','".$sellintro."','".$addpt."'"; $sqlk .= "sellname,sellmodel,sellintro,sellphoto"; } //企業logo if ($_FILES["logo"]["name"] == '') { }else{ $logo1 = "logo"; $addlg = imageUP($logo1); $sqlv .= ",'".$addlg."'"; $sqlk .= ",logo"; } //添加時間ip地址 $sqlv .= ",'".$time."'"; $sqlk .= ",addtime"; $sqlv .= ",'".$reIP."'"; $sqlk .= ",ipadd"; echo "值: " . $sqlv . "<br>"; echo "鍵: " . $sqlk ; if ($chick ==998) { $a = $db->query("INSERT INTO {$DT_PRE}event2017 ($sqlk) VALUES ($sqlv)"); if ($a) { echo "<script>alert('恭喜您提交成功,業務表明會在2個工做日內聯繫您進行進一步溝通'); location.href='http://www.xxx.com/xxx/event.php';</script>"; }else{ echo "<script>alert('入庫錯誤,請聯繫管理人員')</script>"; } } } function imageUP($imgname){//圖片上傳邏輯 $allowedExts = array("gif", "jpeg", "jpg", "png");//許可格式 $temp = explode(".", $_FILES[$imgname]["name"]);//切割文件格式 $extension = end($temp); if ((($_FILES[$imgname]["type"] == "image/gif")//判斷格式及大小 || ($_FILES[$imgname]["type"] == "image/jpeg") || ($_FILES[$imgname]["type"] == "image/jpg") || ($_FILES[$imgname]["type"] == "image/pjpeg") || ($_FILES[$imgname]["type"] == "image/x-png") || ($_FILES[$imgname]["type"] == "image/png")) && ($_FILES[$imgname]["size"] < 204800) && in_array($extension, $allowedExts)) { if ($_FILES[$imgname]["error"] > 0) { echo "錯誤:: " . $_FILES[$imgname]["error"] . "<br>"; } else { if (file_exists(DT_ROOT ."file/upload/event/" . $_FILES[$imgname]["name"]))//判斷路徑是否存在該文件 { echo $_FILES[$imgname]["name"] . " 文件已經存在。 "; } else { move_uploaded_file($_FILES[$imgname]["tmp_name"], DT_ROOT ."/file/upload/event/". $time .$_FILES[$imgname]["name"]);//臨時文件轉存至服務器 $addressz = DT_PATH ."file/upload/event/" . $time .$_FILES[$imgname]["name"];//獲取存儲地址 return $addressz;//返回地址以備入庫 } } } else { echo "<script>alert('請使用不超過200kb的jpg/png/jpeg/gif等格式的圖片')</script>"; $chick = 0; } } function isnum($num){//數字判斷 if (is_numeric($num)) { return true; }else{ return false; } } function ischina($china){//中文判斷 // echo "<script>alert('進判斷來了')</script>"; $pattern = '/[^\x00-\x80]/'; if(eregi('[^\x00-\x7F]', $china )){ return true; }else{ return false; } }