国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php文件上傳代碼

2024-09-04 11:44:58
字體:
來源:轉載
供稿:網友

這是一款完整的php文件上傳實例代碼,支持上傳的類型可以創建類時自定義,可支持的上傳文件類型,代碼如下:

  1. <form name="form1" enctype="multipart/form-data" method="post" action=""
  2.   <label for="filefield"></label> 
  3.   <input type="file" name="filefield" id="filefield"
  4.   <input type="submit" name="button" id="button" value="上傳文件"
  5. </form> 
  6. <?php 
  7. /* 
  8.  * $name;     上傳文件名 
  9.  * $size:    上傳文件大小 
  10.  * $path;     文件原路徑 
  11.  * $newpath:  設置新路徑 
  12.  * $not:      禁止上傳的文件類型數組 
  13.  * $notsize:  限制文件大小的值 
  14.  * $move:     上傳文件源 
  15.  * 
  16.  */ 
  17.  
  18. class fileupload { 
  19.  public $name
  20.  public $size
  21.  public $path
  22.  public $newpath
  23.  public $not = array(); 
  24.  public $notsize
  25.  public $move
  26.  public $allfile = array(); 
  27.     function __construct($name,$size,$path,$newpath,$not,$notsize) { 
  28.      $this ->name = $name
  29.      $this ->size = $size/1048576; 
  30.      $this ->path = $path
  31.      $this ->newpath = $newpath
  32.      $this ->not = explode(',',$not); 
  33.      $this ->notsize = $notsize
  34.         $this ->upload(); 
  35.     } 
  36.     /* 
  37.      * 上傳程序 
  38.      * 首先判斷目錄是否存在 
  39.      * 判斷文件類型及大小 
  40.      */ 
  41.     function upload(){ 
  42.      if(!file_exists($this->newpath)){ 
  43.       echo "<script>alert('該目錄不存在!')</script>"
  44.       return
  45.      }else
  46.             $arr = explode('.',$this->name); 
  47.             if(in_array($arr[1],$this->not)){ 
  48.              echo "<script>alert('該類型文件禁止上傳!')</script>"
  49.              return
  50.             }else if($this->name == ''){ 
  51.              echo "<script>alert('請選擇上傳的文件!')</script>"
  52.              return
  53.             }else if($this->size>$this->notsize){ 
  54.              echo "<script>alert('上傳文件超過規定大小!')</script>"
  55.              return
  56.             }else if(file_exists("$this->newpath"."$this->name")){ 
  57.                 echo "<script>alert('該文件已經存在!')</script>"
  58.                 return
  59.             } 
  60.             else
  61.                $this->move = move_uploaded_file($this->path,$this->newpath.$this->name); 
  62.                $this->move(); 
  63.              } 
  64.          } 
  65.     } 
  66.     /* 
  67.      * 判斷文件上傳是否成功 
  68.      */ 
  69.     function move(){ 
  70.      if($this->move){ 
  71.       echo "<script>alert('文件上傳成功!')</script>"
  72.       return
  73.      }else
  74.       echo "<script>alert('上傳失敗!')</script>"
  75.       return
  76.      } 
  77.     } 
  78.  
  79.  $fu = new fileupload($array[name],$array[size],$array[tmp_name],'./www.survivalescaperooms.com/','exe,rar',5); 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 石台县| 永寿县| 仙桃市| 镇雄县| 南京市| 云林县| 越西县| 溧阳市| 泾源县| 东宁县| 资兴市| 酒泉市| 土默特左旗| 弋阳县| 清远市| 石家庄市| 韩城市| 宜良县| 额敏县| 永靖县| 吉首市| 长丰县| 沁水县| 张掖市| 德保县| 博客| 溆浦县| 灵川县| 扬中市| 驻马店市| 读书| 松潘县| 东丽区| 漳平市| 马山县| 柳河县| 昔阳县| 宁乡县| 额济纳旗| 万宁市| 桐梓县|