用PHP處理圖片檔案的上傳

來源:互聯網
上載者:User
這篇文章主要介紹了關於用PHP處理圖片檔案的上傳,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

1.html檔案

form表單注意。enctype屬性

<form action="goods/goodsAdd.action.php" method="POST" enctype="multipart/form-data">

代碼:

<?phprequire('../../public/common/config.php');$sqlClass = "select * from sort";$rstClass = mysqli_query($conn,$sqlClass);?><p><h4>添加商品</h4><form action="goods/goodsAdd.action.php" method="POST" enctype="multipart/form-data"><ul><li><label for="goodsname">商品名</label><input type="text" name="goodsname" id="goodsname"></li><li><label for="goodsprice">商品價格</label><input type="text" name="goodsprice" id="goodsprice"></li><li><label for="goodsort">商品庫存</label><input type="text" name="goodsort" id="goodsort"></li><li><p>產品分類</p><select name="brand_id"><?phpwhile ($rowClass=mysqli_fetch_assoc($rstClass)) {echo "<option disabled>{$rowClass['name']}</option>";$sqlBrand = "select * from brand where sort_id='{$rowClass[id]}' ";$rstBrand = mysqli_query($conn,$sqlBrand);while ($rowBrand=mysqli_fetch_assoc($rstBrand)) {echo "<option value='{$rowBrand['id']}'>  |-{$rowBrand['name']}</option>";}}?></select></li><li><p>貨架</p><label for="upshelf">上架s</label><input type="radio" name="shelf" id="upshelf" value="1" checked><label for="downshelf">下架d</label><input type="radio" name="shelf" id="downshelf" value="0"></li><li><input type="file" name="img" value=""></li></ul><input type="submit" value="添加商品"></form></p>

查看資料:

    echo "<pre>";      print_r($_POST);      echo "</pre>";      echo "<pre>";      print_r($_FILES);      echo "</pre>";      exit;


測試


。php檔案代碼:

<?php  require('../../public/common/config.php');      // echo "<pre>";      // print_r($_POST);      // echo "</pre>";      // echo "<pre>";      // print_r($_FILES);      // echo "</pre>";      // exit;      $name = $_POST['goodsname'];      $price = $_POST['goodsprice'];      $sort = $_POST['goodsort'];      $shelf = $_POST['shelf'];      $brand_id = $_POST['brand_id'];      //圖片上傳            $src = $_FILES['img']['tmp_name'];      $name = $_FILES['img']['name'];      $ext = array_pop(explode('.', $name));      $dst = '../../public/uploads/'.time().mt_rand().'.'.$ext;      if(move_uploaded_file($src, $dst)){        echo "upload success";        //圖片縮放200*200              }else{        echo "upload  error";      }?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.