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

首頁(yè) > 語(yǔ)言 > PHP > 正文

php文件上傳類(lèi)程序代碼

2024-09-04 11:45:01
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

我們現(xiàn)在只要搜索文件上傳類(lèi)有大把,但是真正好用的上傳類(lèi)不多,下面我介紹這個(gè)文件上傳類(lèi)是我自己使用了很久,非常不錯(cuò)的一個(gè)代碼,大家可參考參考.

php文件上傳類(lèi)程序代碼如下:

  1. <?php 
  2.  /** 
  3.   * 文件上傳類(lèi) 
  4.   */ 
  5.  class uploadFile { 
  6.  
  7.     public $max_size = '1000000';//設(shè)置上傳文件大小 
  8.     public $file_name = 'date';//重命名方式代表以時(shí)間命名,其他則使用給予的名稱(chēng) 
  9.     public $allow_types;//允許上傳的文件擴(kuò)展名,不同文件類(lèi)型用“|”隔開(kāi) 
  10.     public $errmsg = '';//錯(cuò)誤信息 
  11.     public $uploaded = '';//上傳后的文件名(包括文件路徑) 
  12.     public $save_path;//上傳文件保存路徑 
  13.     private $files;//提交的等待上傳文件 
  14.     private $file_type = array();//文件類(lèi)型 
  15.     private $ext = '';//上傳文件擴(kuò)展名 
  16.  
  17.     /** 
  18.      * 構(gòu)造函數(shù),初始化類(lèi) 
  19.      * @access public 
  20.      * @param string $file_name 上傳后的文件名 
  21.      * @param string $save_path 上傳的目標(biāo)文件夾 
  22.      */ 
  23.     public function __construct($save_path = './upload/',$file_name = 'date',$allow_types = '') { 
  24.         $this->file_name   = $file_name;//重命名方式代表以時(shí)間命名,其他則使用給予的名稱(chēng) 
  25.         $this->save_path   = (preg_match('//$/',$save_path)) ? $save_path : $save_path . '/'
  26.         $this->allow_types = $allow_types == '' ? 'jpg|gif|png|zip|rar' : $allow_types
  27.     } 
  28.  
  29.     /** 
  30.      * 上傳文件 
  31.      * @access public 
  32.      * @param $files 等待上傳的文件(表單傳來(lái)的$_FILES[]) 
  33.      * @return boolean 返回布爾值 
  34.      */ 
  35.     public function upload_file($files) { 
  36.         $name = $files['name']; 
  37.         $type = $files['type']; 
  38.         $size = $files['size']; 
  39.         $tmp_name = $files['tmp_name']; 
  40.         $error = $files['error']; 
  41.  
  42.         switch ($error) { 
  43.             case 0 : $this->errmsg = ''
  44.                 break
  45.             case 1 : $this->errmsg = '超過(guò)了php.ini中文件大小'
  46.                 break
  47.             case 2 : $this->errmsg = '超過(guò)了MAX_FILE_SIZE 選項(xiàng)指定的文件大小'
  48.                 break
  49.             case 3 : $this->errmsg = '文件只有部分被上傳'
  50.                 break
  51.             case 4 : $this->errmsg = '沒(méi)有文件被上傳'
  52.                 break
  53.             case 5 : $this->errmsg = '上傳文件大小為0'
  54.                 break
  55.             default : $this->errmsg = '上傳文件失敗!'
  56.                 break
  57.             } 
  58.         if($error == 0 && is_uploaded_file($tmp_name)) { 
  59.             //檢測(cè)文件類(lèi)型 
  60.             if($this->check_file_type($name) == FALSE){ 
  61.                 return FALSE; 
  62.             }//開(kāi)源代碼Vevb.com 
  63.             //檢測(cè)文件大小 
  64.             if($size > $this->max_size){ 
  65.                 $this->errmsg = '上傳文件<font color=red>'.$name.'</font>太大,最大支持<font color=red>'.ceil($this->max_size/1024).'</font>kb的文件'
  66.                 return FALSE; 
  67.             } 
  68.             $this->set_save_path();//設(shè)置文件存放路徑 
  69.             $new_name = $this->file_name != 'date' ? $this->file_name.'.'.$this->ext : date('YmdHis').'.'.$this->ext;//設(shè)置新文件名 
  70.             $this->uploaded = $this->save_path.$new_name;//上傳后的文件名 
  71.             //移動(dòng)文件 
  72.             if(move_uploaded_file($tmp_name,$this->uploaded)){ 
  73.                 $this->errmsg = '文件<font color=red>'.$this->uploaded.'</font>上傳成功!'
  74.                 return TRUE; 
  75.             }else
  76.                 $this->errmsg = '文件<font color=red>'.$this->uploaded.'</font>上傳失敗!'
  77.                 return FALSE; 
  78.             } 
  79.  
  80.         } 
  81.     } 
  82.  
  83.     /** 
  84.      * 檢查上傳文件類(lèi)型 
  85.      * @access public 
  86.      * @param string $filename 等待檢查的文件名 
  87.      * @return 如果檢查通過(guò)返回TRUE 未通過(guò)則返回FALSE和錯(cuò)誤消息 
  88.      */ 
  89.     public function check_file_type($filename){ 
  90.         $ext = $this->get_file_type($filename); 
  91.         $this->ext = $ext
  92.         $allow_types = explode('|',$this->allow_types);//分割允許上傳的文件擴(kuò)展名為數(shù)組 
  93.         //echo $ext; 
  94.         //檢查上傳文件擴(kuò)展名是否在請(qǐng)?jiān)试S上傳的文件擴(kuò)展名中 
  95.         if(in_array($ext,$allow_types)){ 
  96.             return TRUE; 
  97.         }else
  98.             $this->errmsg = '上傳文件<font color=red>'.$filename.'</font>類(lèi)型錯(cuò)誤,只支持上傳<font color=red>'.str_replace('|',',',$this->allow_types).'</font>等文件類(lèi)型!'
  99.             return FALSE; 
  100.         } 
  101.     } 
  102.  
  103.     /** 
  104.      * 取得文件類(lèi)型 
  105.      * @access public 
  106.      * @param string $filename 要取得文件類(lèi)型的目標(biāo)文件名 
  107.      * @return string 文件類(lèi)型 
  108.      */ 
  109.     public function get_file_type($filename){ 
  110.         $info = pathinfo($filename); 
  111.         $ext = $info['extension']; 
  112.         return $ext
  113.     } 
  114.  
  115.     /** 
  116.      * 設(shè)置文件上傳后的保存路徑 
  117.      */ 
  118.     public function set_save_path(){ 
  119.         $this->save_path = (preg_match('//$/',$this->save_path)) ? $this->save_path : $this->save_path . '/'
  120.         if(!is_dir($this->save_path)){ 
  121.             //如果目錄不存在,創(chuàng)建目錄 
  122.             $this->set_dir(); 
  123.         } 
  124.     } 
  125.  
  126.  
  127.     /** 
  128.      * 創(chuàng)建目錄 
  129.      * @access public 
  130.      * @param string $dir 要?jiǎng)?chuàng)建目錄的路徑 
  131.      * @return boolean 失敗時(shí)返回錯(cuò)誤消息和FALSE 
  132.      */ 
  133.     public function set_dir($dir = null){ 
  134.         //檢查路徑是否存在 
  135.         if(!$dir){ 
  136.             $dir = $this->save_path; 
  137.         } 
  138.         if(is_dir($dir)){ 
  139.             $this->errmsg = '需要?jiǎng)?chuàng)建的文件夾已經(jīng)存在!'
  140.         } 
  141.         $dir = explode('/'$dir); 
  142.         foreach($dir as $v){ 
  143.             if($v){ 
  144.                 $d .= $v . '/'
  145.                 if(!is_dir($d)){ 
  146.                     $state = mkdir($d, 0777); 
  147.                     if(!$state
  148.                         $this->errmsg = '在創(chuàng)建目錄<font color=red>' . $d . '時(shí)出錯(cuò)!'
  149.                 } 
  150.             } 
  151.         } 
  152.         return true; 
  153.     } 
  154.  } 
  155.  
  156. /************************************************* 
  157.  * 圖片處理類(lèi) 
  158.  * 
  159.  * 可以對(duì)圖片進(jìn)行生成縮略圖,打水印等操作 
  160.  * 本類(lèi)默認(rèn)編碼為UTF8 如果要在GBK下使用請(qǐng)將img_mark方法中打中文字符串水印iconv注釋去掉 
  161.  * 
  162.  * 由于UTF8漢字和英文字母大小(像素)不好確定,在中英文混合出現(xiàn)太多時(shí)可能會(huì)出現(xiàn)字符串偏左 
  163.  * 或偏右,請(qǐng)根據(jù)項(xiàng)目環(huán)境對(duì)get_mark_xy方法中的$strc_w = strlen($this->mark_str)*7+5進(jìn) 
  164.  * 行調(diào)整 
  165.  * 需要GD庫(kù)支持,為更好使用本類(lèi)推薦使用GD庫(kù)2.0+ 
  166.  * 
  167.  * @author kickflip@php100 QQ263340607 
  168.  *************************************************/ 
  169.  
  170.  class uploadImg extends uploadFile { 
  171.  
  172.     public $mark_str = 'kickflip@php100';  //水印字符串 
  173.     public $str_r = 0; //字符串顏色R 
  174.     public $str_g = 0; //字符串顏色G 
  175.     public $str_b = 0; //字符串顏色B 
  176.     public $mark_ttf = './upload/SIMSUN.TTC'//水印文字字體文件(包含路徑) 
  177.     public $mark_logo = './upload/logo.png';    //水印圖片 
  178.     public $resize_h;//生成縮略圖高 
  179.     public $resize_w;//生成縮略圖寬 
  180.     public $source_img;//源圖片文件 
  181.     public $dst_path = './upload/';//縮略圖文件存放目錄,不填則為源圖片存放目錄 
  182.  
  183.     /** 
  184.      * 生成縮略圖 生成后的圖 
  185.      * @access public 
  186.      * @param integer $w 縮小后圖片的寬(px) 
  187.      * @param integer $h 縮小后圖片的高(px) 
  188.      * @param string $source_img 源圖片(路徑+文件名) 
  189.      */ 
  190.     public function img_resized($w,$h,$source_img = NULL){ 
  191.         $source_img = $source_img == NULL ? $this->uploaded : $source_img;//取得源文件的地址,如果為空則默認(rèn)為上次上傳的圖片 
  192.         if(!is_file($source_img)) { //檢查源圖片是否存在 
  193.             $this->errmsg = '文件'.$source_img.'不存在'
  194.             return FALSE; 
  195.         } 
  196.         $this->source_img = $source_img
  197.         $img_info = getimagesize($source_img); 
  198.         $source = $this->img_create($source_img); //創(chuàng)建源圖片 
  199.         $this->resize_w = $w
  200.         $this->resize_h = $h
  201.         $thumb = imagecreatetruecolor($w,$h); 
  202.         imagecopyresized($thumb,$source,0,0,0,0,$w,$h,$img_info[0],$img_info[1]);//生成縮略圖片 
  203.         $dst_path = $this->dst_path == '' ? $this->save_path : $this->dst_path; //取得目標(biāo)文件夾路徑 
  204.         $dst_path = (preg_match('//$/',$dst_path)) ? $dst_path : $dst_path . '/';//將目標(biāo)文件夾后加上/ 
  205.         if(!is_dir($dst_path)) $this->set_dir($dst_path); //如果不存在目標(biāo)文件夾則創(chuàng)建 
  206.         $dst_name = $this->set_newname($source_img); 
  207.         $this->img_output($thumb,$dst_name);//輸出圖片 
  208.         imagedestroy($source); 
  209.         imagedestroy($thumb); 
  210.     } 
  211.  
  212.     /** 
  213.      *打水印 
  214.      *@access public 
  215.      *@param string $source_img 源圖片路徑+文件名 
  216.      *@param integer $mark_type 水印類(lèi)型(1為英文字符串,2為中文字符串,3為圖片logo,默認(rèn)為英文字符串) 
  217.      *@param integer $mark_postion 水印位置(1為左下角,2為右下角,3為左上角,4為右上角,默認(rèn)為右下角); 
  218.      *@return 打上水印的圖片 
  219.      */ 
  220.     public function img_mark($source_img = NULL,$mark_type = 1,$mark_postion = 2) { 
  221.         $source_img = $source_img == NULL ? $this->uploaded : $source_img;//取得源文件的地址,如果為空則默認(rèn)為上次上傳的圖片 
  222.         if(!is_file($source_img)) { //檢查源圖片是否存在 
  223.             $this->errmsg = '文件'.$source_img.'不存在'
  224.             return FALSE; 
  225.         } 
  226.         $this->source_img = $source_img
  227.         $img_info = getimagesize($source_img); 
  228.         $source = $this->img_create($source_img); //創(chuàng)建源圖片 
  229.         $mark_xy = $this->get_mark_xy($mark_postion);//取得水印位置 
  230.         $mark_color = imagecolorallocate($source,$this->str_r,$this->str_g,$this->str_b); 
  231.  
  232.         switch($mark_type) { 
  233.  
  234.             case 1 : //加英文字符串水印 
  235.             $str = $this->mark_str; 
  236.             imagestring($source,5,$mark_xy[0],$mark_xy[1],$str,$mark_color); 
  237.             $this->img_output($source,$source_img); 
  238.             break
  239.  
  240.             case 2 : //加中文字符串水印 
  241.             if(!is_file($this->mark_ttf)) { //檢查字體文件是否存在 
  242.                 $this->errmsg = '打水印失敗:字體文件'.$this->mark_ttf.'不存在!'
  243.             return FALSE; 
  244.             } 
  245.             $str = $this->mark_str; 
  246.             //$str = iconv('gbk','utf-8',$str);//轉(zhuǎn)換字符編碼 如果使用GBK編碼請(qǐng)去掉此行注釋 
  247.             imagettftext($source,12,0,$mark_xy[2],$mark_xy[3],$mark_color,$this->mark_ttf,$str); 
  248.             $this->img_output($source,$source_img); 
  249.             break
  250.  
  251.             case 3 : //加圖片水印 
  252.             if(is_file($this->mark_logo)){  //如果存在水印logo的圖片則取得logo圖片的基本信息,不存在則退出 
  253.                 $logo_info = getimagesize($this->mark_logo); 
  254.             }else
  255.                 $this->errmsg = '打水印失敗:logo文件'.$this->mark_logo.'不存在!'
  256.                 return FALSE; 
  257.             } 
  258.  
  259.             $logo_info = getimagesize($this->mark_logo); 
  260.             if($logo_info[0]>$img_info[0] || $logo_info[1]>$img_info[1]) { //如果源圖片小于logo大小則退出 
  261.                 $this->errmsg = '打水印失敗:源圖片'.$this->source_img.'比'.$this->mark_logo.'小!'
  262.                 return FALSE; 
  263.             } 
  264.  
  265.             $logo = $this->img_create($this->mark_logo); 
  266.             imagecopy ( $source$logo$mark_xy[4], $mark_xy[5], 0, 0, $logo_info[0], $logo_info[1]); 
  267.             $this->img_output($source,$source_img); 
  268.             break
  269.  
  270.             default//其它則為文字圖片 
  271.             $str = $this->mark_str; 
  272.             imagestring($source,5,$mark_xy[0],$mark_xy[1],$str,$mark_color); 
  273.             $this->img_output($source,$source_img); 
  274.             break
  275.         } 
  276.         imagedestroy($source); 
  277.     } 
  278.  
  279.     /** 
  280.      * 取得水印位置 
  281.      * @access private 
  282.      * @param integer $mark_postion 水印的位置(1為左下角,2為右下角,3為左上角,4為右上角,其它為右下角) 
  283.      * @return array $mark_xy 水印位置的坐標(biāo)(索引0為英文字符串水印坐標(biāo)X,索引1為英文字符串水印坐標(biāo)Y, 
  284.      * 索引2為中文字符串水印坐標(biāo)X,索引3為中文字符串水印坐標(biāo)Y,索引4為水印圖片坐標(biāo)X,索引5為水印圖片坐標(biāo)Y) 
  285.      */ 
  286.     private function get_mark_xy($mark_postion){ 
  287.         $img_info = getimagesize($this->source_img); 
  288.  
  289.         $stre_w = strlen($this->mark_str)*9+5 ; //水印英文字符串的長(zhǎng)度(px)(5號(hào)字的英文字符大小約為9px 為了美觀再加5px) 
  290.         //(12號(hào)字的中文字符大小為12px,在utf8里一個(gè)漢字長(zhǎng)度為3個(gè)字節(jié)一個(gè)字節(jié)4px 而一個(gè)英文字符長(zhǎng)度一個(gè)字節(jié)大小大約為9px 
  291.         // 為了在中英文混合的情況下顯示完全 設(shè)它的長(zhǎng)度為字節(jié)數(shù)*7px) 
  292.         $strc_w = strlen($this->mark_str)*7+5 ; //水印中文字符串的長(zhǎng)度(px) 
  293.  
  294.         if(is_file($this->mark_logo)){ //如果存在水印logo的圖片則取得logo圖片的基本信息 
  295.             $logo_info = getimagesize($this->mark_logo); 
  296.         } 
  297.  
  298.         //由于imagestring函數(shù)和imagettftext函數(shù)中對(duì)于字符串開(kāi)始位置不同所以英文和中文字符串的Y位置也有所不同 
  299.         //imagestring函數(shù)是從文字的左上角為參照 imagettftext函數(shù)是從文字左下角為參照 
  300.         switch($mark_postion){ 
  301.  
  302.             case 1: //位置左下角 
  303.             $mark_xy[0] = 5; //水印英文字符串坐標(biāo)X 
  304.             $mark_xy[1] = $img_info[1]-20;//水印英文字符串坐標(biāo)Y 
  305.             $mark_xy[2] = 5; //水印中文字符串坐標(biāo)X 
  306.             $mark_xy[3] = $img_info[1]-5;//水印中文字符串坐標(biāo)Y 
  307.             $mark_xy[4] = 5;//水印圖片坐標(biāo)X 
  308.             $mark_xy[5] = $img_info[1]-$logo_info[1]-5;//水印圖片坐標(biāo)Y 
  309.             break
  310.  
  311.             case 2: //位置右下角 
  312.             $mark_xy[0] = $img_info[0]-$stre_w//水印英文字符串坐標(biāo)X 
  313.             $mark_xy[1] = $img_info[1]-20;//水印英文字符串坐標(biāo)Y 
  314.             $mark_xy[2] = $img_info[0]-$strc_w//水印中文字符串坐標(biāo)X 
  315.             $mark_xy[3] = $img_info[1]-5;//水印中文字符串坐標(biāo)Y 
  316.             $mark_xy[4] = $img_info[0]-$logo_info[0]-5;//水印圖片坐標(biāo)X 
  317.             $mark_xy[5] = $img_info[1]-$logo_info[1]-5;//水印圖片坐標(biāo)Y 
  318.             break
  319.  
  320.             case 3: //位置左上角 
  321.             $mark_xy[0] = 5; //水印英文字符串坐標(biāo)X 
  322.             $mark_xy[1] = 5;//水印英文字符串坐標(biāo)Y 
  323.             $mark_xy[2] = 5; //水印中文字符串坐標(biāo)X 
  324.             $mark_xy[3] = 15;//水印中文字符串坐標(biāo)Y 
  325.             $mark_xy[4] = 5;//水印圖片坐標(biāo)X 
  326.             $mark_xy[5] = 5;//水印圖片坐標(biāo)Y 
  327.             break
  328.  
  329.             case 4: //位置右上角 
  330.             $mark_xy[0] = $img_info[0]-$stre_w//水印英文字符串坐標(biāo)X 
  331.             $mark_xy[1] = 5;//水印英文字符串坐標(biāo)Y 
  332.             $mark_xy[2] = $img_info[0]-$strc_w//水印中文字符串坐標(biāo)X 
  333.             $mark_xy[3] = 15;//水印中文字符串坐標(biāo)Y 
  334.             $mark_xy[4] = $img_info[0]-$logo_info[0]-5;//水印圖片坐標(biāo)X 
  335.             $mark_xy[5] = 5;//水印圖片坐標(biāo)Y 
  336.             break
  337.  
  338.             default : //其它默認(rèn)為右下角 
  339.             $mark_xy[0] = $img_info[0]-$stre_w//水印英文字符串坐標(biāo)X 
  340.             $mark_xy[1] = $img_info[1]-5;//水印英文字符串坐標(biāo)Y 
  341.             $mark_xy[2] = $img_info[0]-$strc_w//水印中文字符串坐標(biāo)X 
  342.             $mark_xy[3] = $img_info[1]-15;//水印中文字符串坐標(biāo)Y 
  343.             $mark_xy[4] = $img_info[0]-$logo_info[0]-5;//水印圖片坐標(biāo)X 
  344.             $mark_xy[5] = $img_info[1]-$logo_info[1]-5;//水印圖片坐標(biāo)Y 
  345.             break
  346.         } 
  347.         return $mark_xy
  348.     } 
  349.  
  350.     /** 
  351.      * 創(chuàng)建源圖片 
  352.      * @access private 
  353.      * @param string $source_img 源圖片(路徑+文件名) 
  354.      * @return img 從目標(biāo)文件新建的圖像 
  355.      */ 
  356.     private function img_create($source_img) { 
  357.         $info = getimagesize($source_img); 
  358.         switch ($info[2]){ 
  359.             case 1: 
  360.             if(!function_exists('imagecreatefromgif')){ 
  361.                 $source = @imagecreatefromjpeg($source_img); 
  362.             }else
  363.                 $source = @imagecreatefromgif($source_img); 
  364.             } 
  365.             break
  366.             case 2: 
  367.             $source = @imagecreatefromjpeg($source_img); 
  368.             break
  369.             case 3: 
  370.             $source = @imagecreatefrompng($source_img); 
  371.             break
  372.             case 6: 
  373.             $source = @imagecreatefromwbmp($source_img); 
  374.             break
  375.             default
  376.             $source = FALSE; 
  377.             break
  378.         } 
  379.         return $source
  380.     } 
  381.  
  382.  /** 
  383.   * 重命名圖片 
  384.   * @access private 
  385.   * @param string $source_img 源圖片路徑+文件名 
  386.   * @return string $dst_name 重命名后的圖片名(路徑+文件名) 
  387.   */ 
  388.  private function set_newname($sourse_img) { 
  389.     $info = pathinfo($sourse_img); 
  390.     $new_name = $this->resize_w.'_'.$this->resize_h.'_'.$info['basename'];//將文件名修改為:寬_高_(dá)文件名 
  391.     if($this->dst_path == ''){ //如果存放縮略圖路徑為空則默認(rèn)為源文件同文件夾 
  392.         $dst_name = str_replace($info['basename'],$new_name,$sourse_img); 
  393.     }else
  394.         $dst_name = $this->dst_path.$new_name
  395.     } 
  396.     return $dst_name
  397.  } 
  398.  
  399.  /** 
  400.   * 輸出圖片 
  401.   * @access private 
  402.   * @param $im 處理后的圖片 
  403.   * @param $dst_name 輸出后的的圖片名(路徑+文件名) 
  404.   * @return 輸出圖片 
  405.   */ 
  406.  public function img_output($im,$dst_name) { 
  407.     $info = getimagesize($this->source_img); 
  408.     switch ($info[2]){ 
  409.             case 1: 
  410.             if(!function_exists('imagegif')){ 
  411.                 imagejpeg($im,$dst_name); 
  412.             }else
  413.                 imagegif($im$dst_name); 
  414.             } 
  415.             break
  416.             case 2: 
  417.             imagejpeg($im,$dst_name); 
  418.             break
  419.             case 3: 
  420.             imagepng($im,$dst_name); 
  421.             break
  422.             case 6: 
  423.             imagewbmp($im,$dst_name); 
  424.             break
  425.         } 
  426.  } 
  427.  
  428.  } 
  429. ?> 

使用方法,代碼如下:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>上傳文件</title></head><body leftmargin="0" topmargin="0"><table cellpadding="2" cellspacing="1" border="0" height="100%" align="left"><form action='wend.php?action=upload'  method='post' enctype='multipart/form-data'><tr ><td  valign='middle'><input type='file' name='uploadfile'><input name='submit' type='submit' value='上傳'></td></tr></form></table</body></html> 

php處理文件,調(diào)用上面的類(lèi)文件,然后再如下操作,代碼如下:

  1. $action = addslashes($_GET['action']); 
  2. if$action =="udd"
  3.  $state=uploadfile('uploadfile'); 
  4.  //echo $state['err'];exit; 
  5.  if($state['err']){ 
  6.   die('<script>alert("上傳出錯(cuò):'.$state['err'].'");history.go(-1);</script>'); 
  7.  } 
  8.  else 
  9.  { 
  10.   echo '文件己上傳!<a href="upp.php">刪除重傳</a>'
  11.    
  12.  } 
  13.  
  14.  
  15. else
  16.  echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
  17.  echo '<html xmlns="http://www.w3.org/1999/xhtml">'
  18.  echo '<head>'
  19.  echo '<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />'
  20.  echo '<title>上傳文件</title>'
  21.  //echo "<meta http-equiv="content-type" content="text/html; charset=gb2312">"; 
  22.  echo '</head>'
  23.  echo "<body leftmargin="0" topmargin="0">"
  24.  echo "<table cellpadding="2" cellspacing="1" border="0" height="100%" align="left">"
  25.  echo "<form action='abc.php?action=udd'  method='post' enctype='multipart/form-data'>"
  26.  echo "<tr ><td  valign='middle'>"
  27.  echo "<input type='file' name='uploadfile'>"
  28.  echo "<input name='submit' type='submit' value='上傳'>"
  29.  echo "</td></tr>"
  30.  echo "</form>"
  31.  echo "</table"
  32.  echo "</body>"
  33.  echo '</html>'

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宜兴市| 会宁县| 夏河县| 洪洞县| 江北区| 五家渠市| 大渡口区| 阳城县| 台东市| 巫溪县| 即墨市| 屏东市| 望奎县| 双柏县| 霞浦县| 汉源县| 潍坊市| 海林市| 来宾市| 绥阳县| 城步| 青龙| 天镇县| 龙江县| 潜山县| 安义县| 鄂温| 天全县| 兴文县| 普定县| 涿鹿县| 措美县| 舟山市| 东海县| 沅江市| 博罗县| 高雄市| 雷山县| 琼结县| 莒南县| 祁东县|