无码色色,久久久久久免费精品喷水,美女把胸罩解开让男生摸,欧美一级在线观看视频,色亚洲天堂,色综合天天综合给合国产

咨詢電話:023-88959644    24小時(shí)服務(wù)熱線:400-023-8809
NEWS CENTER ·
新聞動(dòng)態(tài)
關(guān)注中技互聯(lián) 關(guān)注前沿

php中最簡(jiǎn)單的上傳類代碼怎么寫?

發(fā)表日期:2012-02-14    文章編輯:張小川    瀏覽次數(shù):9    標(biāo)簽:

這個(gè)是我昨晚寫的一個(gè)超簡(jiǎn)單的上傳類,只要 $up->upload($_FILES['imgfile']);  即可。 一條語(yǔ)句搞定上傳
送給所有草根的個(gè)人站長(zhǎng)

上傳文件:
up.php
<?php
//驗(yàn)證
if(empty($_COOKIE['login'])) {
        die('index');
}
//加載類
include_once("_inc/class_uppic.php");
//上傳
if(!empty($_GET['action']) && $_GET['action'] == "upload"){
        $up->upload($_FILES['imgfile']);
        echo "上傳成功!文件名:{$up->new_url} <a href=?yes>重新上傳</a>";
}
?>

<form action="?action=upload" method="post" enctype="multipart/form-data">
圖片來(lái)源:<input type="file" name="imgfile" style="width:200px;height:25px;">
<input type="submit" name="submit" value="上傳" style="width:50px;height:25px;">

//================分割線==============

類文件:
class_uppic.php
<?php
/*
        power by jtxxol.com
        2011-06-20
*/
$up=new class_uppic;
class class_uppic{
       
        function __construct(){
                //保存目錄
                $this->save_path='/uploadfile/'; 
                //文件鏈接
                $this->save_url='/uploadfile/'; 
                //允許大小 300k
                $this->allow_size=300000;
                //允許類型
                $this->allow_ext='jpg,jpeg,gif,png';
                //新文件名
                $this->new_name=date("YmdHis").rand(10,99);
                //初始化錯(cuò)誤提示
                $this->err='';
        }
        //上傳
        function upload($arr){
                $this->file=$arr;
                //初始化設(shè)置
                $this->allow_ext=explode(',',$this->allow_ext);
                $this->save_path=$_SERVER['DOCUMENT_ROOT'].$this->save_path.date('Y-m').'/';
                $this->save_url=$this->save_url.date('Y-m').'/';
                //獲得擴(kuò)展名
                $temp_arr = explode(".", $this->file['name']);
                $file_ext = array_pop($temp_arr);
                $file_ext = trim(strtolower($file_ext));
                //檢查類型
                if(!in_array($file_ext,$this->allow_ext)){        
                        $this->err="上傳圖片類型錯(cuò)誤";        
                }
                //檢查大小
                if($this->file['size']>$this->allow_size){        
                        $this->err="文件超出限制大小";        
                }
                //遞歸建立目錄
                $this->creatdir($this->save_path);
                //上傳后的路徑
                $this->new_path=$this->save_path.$this->new_name.'.'.$file_ext;
                $this->new_url =$this->save_url.$this->new_name.'.'.$file_ext;
                //檢查錯(cuò)誤
                if (!empty($this->err)){
                        $this->show($this->err);
                }
                //上傳
                if( !move_uploaded_file($this->file['tmp_name'],$this->new_path) ) {
                        $this->err= "上傳文件出錯(cuò)";
                        $this->show($this->err);
                }
        }
        //建立目錄
        function creatdir($Dir)
        {
                if (is_dir($Dir))
                        return true;
                if (@ mkdir($Dir,0777))
                        return true;
                if (!$this->creatdir(dirname($Dir)))
                         return false;
                return mkdir($Dir,0777);
        }
        //錯(cuò)誤提示        
        function show($errorstr){        
                echo "<script language=javascript>alert('$errorstr');location='javascript:history.go(-1);';</script>";        
                exit();        
        }       
}        
?>

如沒(méi)特殊注明,文章均為中技互聯(lián)原創(chuàng),轉(zhuǎn)載請(qǐng)注明來(lái)自www.tmsmall666.cn
相關(guān)新聞

CopyrightZJCOO technology Co., LTD. All Rights Reserved.    

渝ICP 備11003429號(hào)

  • qq客服
  • 公眾號(hào)
  • 手機(jī)版
  • 新浪微博