<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. php語言

    php上傳圖片客戶端和服務器端實現方法

    時間:2025-02-09 03:15:56 php語言 我要投稿
    • 相關推薦

    php上傳圖片客戶端和服務器端實現方法

      文章主要介紹了php上傳圖片客戶端和服務器端實現方法,涉及php操作文件的技巧,涉及圖片后綴驗證、文件重命名等常用方法,具有一定參考借鑒價值,需要的朋友可以參考下。

    php上傳圖片客戶端和服務器端實現方法

      本文實例講述了php上傳圖片客戶端和服務器端實現方法。分享給大家供大家參考。具體如下:

      前臺表單代碼

      ?

      1

      2

      3

      4

      <form name="form1" method="post" action="admin_upfile.php" enctype="multipart/form-data">

      <input type="file" name="pic">

      <input type="submit" name="Submit" value="開始上傳" class="button">

      </form>

      后端php代碼

      ?

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19

      20

      21

      22

      23

      24

      25

      26

      27

      28

      29

      30

      31

      32

      33

      34

      35

      36

      37

      38

      39

      40

      41

      42

      43

      <?php

      //這里上傳 $upsize判斷上傳文件的大小

      $uppath = "/attached/"; //文件上傳路徑

      //轉換根目錄的路徑

      if (strpos($uppath, "/") == 0)

      {

      $i = 0;

      $thpath = $_SERVER["SCRIPT_NAME"];

      $thpath = substr($thpath, 1, strlen($thpath));

      while (strripos($thpath, "/") !== false)

      {

      $thpath = substr($thpath, strpos($thpath, "/") + 1, strlen($thpath));

      $i = ++$i;

      }

      $pp = "";

      for ($j = 0; $j < $i; ++$j)

      {

      $pp .= "../";

      }

      $uppaths = $pp . substr($uppath, 1, strlen($thpath));

      }

      $filename = date("y-m-d");

      if (is_dir($uppaths . $filename) != TRUE)

      mkdir($uppaths . $filename, 0777);

      $f = $_FILES['pic'];

      if ($f["type"] != "image/gif" && $f["type"] != "image/pjpeg" && $f["type"] != "image/jpeg" && $f["type"] != "image/x-png")

      {

      echo "<script>alert('只能上傳圖片格式的文件');window.close()</script>";

      return false;

      }

      //獲得文件擴展名

      $temp_arr = explode(".", $f["name"]);

      $file_ext = array_pop($temp_arr);

      $file_ext = trim($file_ext);

      $file_ext = strtolower($file_ext);

      //新文件名

      $new_file_name = md5(date("YmdHis")) . '.' . $file_ext;

      echo $dest = $uppaths . $filename . "/" . date("ymdhis") . "_" .

      $new_file_name; //設置文件名為日期加上文件名避免重復 上傳目錄

      echo $dest1 = $uppath . $filename . "/" . date("ymdhis") . "_" .

      $new_file_name; //設置文件名為日期加上文件名避免重復

      $r = move_uploaded_file($f['tmp_name'], $dest);

      ?>

      希望本文所述對大家的php程序設計有所幫助。

    【php上傳圖片客戶端和服務器端實現方法】相關文章:

    簡單PHP上傳圖片的方法11-05

    PHP實現文件上傳和多文件上傳07-31

    PHP圖片文件怎么上傳實現代碼10-14

    PHP圖片上傳類帶圖片顯示08-19

    jQuery Mobile + PHP實現文件上傳10-20

    php實現通過ftp上傳文件07-07

    php多圖片上傳的簡單例子10-09

    php上傳與刪除圖片的簡單范例10-13

    PHP實現大文件上傳源代碼10-21

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人