亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP ?? ?? ???? ???? - ?? ??

??? ??? ?? ??? ???????.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加產品</title>
    <style type="text/css">
        #cnt{
            width:400px;
            height:400px;
            margin-top:15px;
            margin-left: 15px;
        }
    </style>
</head>
<body>
    <div id="cnt">
        <form method="post" action="addproduct.php" enctype="multipart/form-data">
            產品名稱:<input type="text" name="title" id="title"></br></br>
            上傳文件:<input type="file" name="myFile"></br></br>
            產品價格:<input type="text" name="price"></br></br>
            <input type="submit" value="添加產品">
        </form>
    </div>
</body>
</html>

? ??? ???? ?? ???? ????. ?? html ?????. ?? ???? ?????. form
??? ???? ? ??? ?????.

??? addproduct.php ???? ?????

? ???? ?????

<?php
    require_once('conn.php');
    //接受文件,臨時文件信息
    $fileinfo=$_FILES["myFile"];//降維操作
    $filename=$fileinfo["name"];
    $tmp_name=$fileinfo["tmp_name"];
    $size=$fileinfo["size"];
    $error=$fileinfo["error"];
    $type=$fileinfo["type"];
 
    //服務器端設定限制
    $maxsize=10485760;//10M,10*1024*1024
    $allowExt=array('jpeg','jpg','png','gif');//允許上傳的文件類型(拓展名
    $ext=pathinfo($filename,PATHINFO_EXTENSION);//提取上傳文件的拓展名
    //目標存放文件夾
    $path="../uploads";
    if (!file_exists($path)) {  //當目錄不存在,就創(chuàng)建目錄
      mkdir($path,0777,true);//創(chuàng)建目錄
      chmod($path, 0777);//改變文件模式,所有人都有執(zhí)行權限、寫權限、度權限
    }
    //得到唯一的文件名!防止因為文件名相同而產生覆蓋
    $uniName=md5(uniqid(microtime(true),true)).".$ext";

    //md5加密,uniqid產生唯一id,microtime做前綴
    //目標存放文件地址
    $destination=$path."/".$uniName;
    //當文件上傳成功,存入臨時文件夾,服務器端開始判斷
    if ($error==0) {
      if ($size>$maxsize) {
        exit("上傳文件過大!");
      }
      if (!in_array($ext, $allowExt)) {
        exit("非法文件類型");
      }
      if (!is_uploaded_file($tmp_name)) {
        exit("上傳方式有誤,請使用post方式");
      }
      //判斷是否為真實圖片(防止偽裝成圖片的病毒一類的
      if (!getimagesize($tmp_name)) {//getimagesize真實返回數(shù)組,否則返回false
        exit("不是真正的圖片類型");
      }
      //move_uploaded_file($tmp_name, "uploads/".$filename);
      if (@move_uploaded_file($tmp_name, $destination)) {//@錯誤抑制符,不讓用戶看到警告
        echo "文件".$filename."上傳成功!";
      }else{
        echo "文件".$filename."上傳失敗!";
      } 
    }else{
      switch ($error){
        case 1:echo "超過了上傳文件的最大值,請上傳2M以下文件";break;
        case 2:echo "上傳文件過多,請一次上傳20個及以下文件!";break;
        case 3:echo "文件并未完全上傳,請再次嘗試!";break;
        case 4:echo "未選擇上傳文件!";break;
        case 7:echo "沒有臨時文件夾";break;
      }
    }

    $title = $_POST['title'];
    $imagename = $uniName;
    $price = $_POST['price'];
    $goodtime = time();
    
    $sql  = "insert into `product`(title,imgname,price,goodtime) values('$title','$imagename','$price','$goodtime')";
    $res = mysql_query($sql);
    if($res){
        echo "<script>alert('添加產品成功');location.href='product.php';</script>";
    }else{
        echo "<script>alert('添加產品失敗');location.href='product.php';</script>";
    }
?>

??? ???? ??? ??? ? ?????. ???? ??? ???? ??? ????. ?? ???? ?????. ??

???? ??
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>添加產品</title> <style type="text/css"> #cnt{ width:400px; height:400px; margin-top:15px; margin-left: 15px; } </style> </head> <body> <div id="cnt"> <form method="post" action="addproduct.php" enctype="multipart/form-data"> 產品名稱:<input type="text" name="title" id="title"></br></br> 上傳文件:<input type="file" name="myFile"></br></br> 產品價格:<input type="text" name="price"></br></br> <input type="submit" value="添加產品"> </form> </div> </body> </html>