PHP上傳類,分享給大家,不足之處請見諒!該如何處理

來源:互聯網
上載者:User
PHP上傳類,分享給大家,不足之處請見諒!
不足之處請高手見諒!

PHP code
/*** 檔案上傳類 kangyangyang 2010-06-07* $loadfile 要上傳的檔案的檔案域* $loadpath 檔案存放路徑* $loadhold 保留檔案原名* $loadsize 檔案大小限制 //預設是2048KB* $loadtype 檔案類型限制 //預設支援 jpg|jpeg|gif|png|txt|rar|zip**/class uploadfile{private $loadfile;private $loadpath;private $loadsize;private $loadtype;private $loadhold = false;private $chkfile = true;private $file_name;private $extend_type;private $set_name;private $set_size;private $set_path;private $set_create_name;private $get_error;//建構函式function __construct($loadfile,$loadpath,$loadhold = false,$loadsize="2097152",$loadtype="jpg|jpeg|gif|png|txt|rar|zip"){   $this->loadfile = $loadfile;   $this->loadpath = $loadpath;   $this->loadsize = $loadsize;   $this->loadtype = $loadtype;   $this->loadhold = $loadhold;   $this->filecheck();}//檔案上傳function filecheck(){  $filename = $_FILES[$this->loadfile]['name']; //檔案名稱  $filetype = $_FILES[$this->loadfile]['type']; //檔案類型  $filesize = $_FILES[$this->loadfile]['size']; //檔案大小  $filepath = $_FILES[$this->loadfile]['tmp_name']; //臨時檔案  $fileerror= $_FILES[$this->loadfile]['error']; //錯誤碼  if($fileerror <= 0 && $filename != ""){   if($this->loadsize >= $filesize){    $this->set_size = $filesize;    $ext = explode(".",$filename);    $this->set_name = $ext;    $ext_type = strtolower($ext[count($ext)-1]);    $this->extend_type = $ext_type;    $chk_type = explode("|",$this->loadtype);    if(in_array($ext_type,$chk_type)){     $f_path = $this->get_folder();     $this->set_create_name = $createname = time().rand(1,9999);     $this->file_name = $createname.".".$ext_type;     if($this->loadhold){      $file_path = $f_path.$filename;      $this->set_path = $file_path;     }else{      $file_path = $f_path.$this->file_name;      $this->set_path = $file_path;     }     $ckfile = move_uploaded_file($filepath,$file_path);     if(!$ckfile){      $this->chefile = false;     }    }else{     $this->chkfile = false;    }   }else{    $this->chkfile = false;   }  }else{   $this->chkfile = false;   $this->get_error = $fileerror;  }}//產生的檔案名稱function get_CreateName(){  if($this->CheckFile()){   if(!$this->loadhold){    return $this->set_create_name;   }  }}//返迴文件夾路徑function get_folder(){  if($this->CheckFile()){   if(!file_exists($this->loadpath)){    mkdir($this->loadpath,0777,true);    chmod($this->loadpath,0777);   }   return $this->loadpath;  }}//副檔名function get_type(){  if($this->CheckFile()){   return $this->extend_type;  }}//檔案名稱"不包括副檔名"function get_name(){  if($this->CheckFile()){   $filename = $this->set_name;   unset($filename[count($filename)-1]);   return implode(".",$filename);  }}//返迴文件大小function get_size(){  if($this->CheckFile()){   return $this->set_size;  }}//返迴文件全路徑function get_path(){  if($this->CheckFile()){   return  $this->set_path;  }}//檔案是否上傳成功function CheckFile(){  return $this->chkfile;}//擷取錯誤碼function get_error(){  if($this->CheckFile()){   return $this->get_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.