- class upphoto{
- public $previewsize=0.125 ; //預覽圖片比例
- public $preview=0; //是否產生預覽,是為1,否為0
- public $datetime; //隨機數
- public $ph_name; //上傳圖片檔案名稱
- public $ph_tmp_name; //圖片臨時檔案名稱
- public $ph_path="../userimg/"; //上傳檔案存放路徑
- public $ph_type; //圖片類型
- public $ph_size; //圖片大小
- public $imgsize; //上傳圖片尺寸,用於判斷顯示比例
- public $al_ph_type=array(image/jpg,image/jpeg,image/png,image/pjpeg,image/gif,image/bmp,image/x-png); //允許上傳圖片類型
- public $al_ph_size=1000000; //允許上傳檔案大小
- function __construct(){
- $this->set_datatime();
- }
- function set_datatime(){
- $this->datetime=date("YmdHis");
- }
- //擷取檔案類型
- function get_ph_type($phtype){
- $this->ph_type=$phtype;
- }
- //擷取檔案大小
- function get_ph_size($phsize){
- $this->ph_size=$phsize."
";
- }
- //擷取上傳臨時檔案名稱
- function get_ph_tmpname($tmp_name){
- $this->ph_tmp_name=$tmp_name;
- $this->imgsize=getimagesize($tmp_name);
- }
- //擷取原檔案名稱
- function get_ph_name($phname){
- $this->ph_name=$this->ph_path.$this->datetime.strrchr($phname,"."); //strrchr擷取檔案的點最後一次出現的位置
- //$this->ph_name=$this->datetime.strrchr($phname,"."); //strrchr擷取檔案的點最後一次出現的位置
- return $this->ph_name;
- }
- // 判斷上傳檔案存放目錄
- function check_path(){
- if(!file_exists($this->ph_path)){
- mkdir($this->ph_path);
- }
- }
- //判斷上傳檔案是否超過允許大小
- function check_size(){
- if($this->ph_size>$this->al_ph_size){
- $this->showerror("上傳圖片超過2000KB");
- }
- }
- //判斷檔案類型
- function check_type(){
- if(!in_array($this->ph_type,$this->al_ph_type)){
- $this->showerror("上傳圖片類型錯誤");
- }
- }
- //上傳圖片
- function up_photo(){
- if(!move_uploaded_file($this->ph_tmp_name,$this->ph_name)){
- $this->showerror("上傳檔案出錯");
- }
- }
- //圖片預覽
- function showphoto(){
- if($this->preview==1){
- if($this->imgsize[0]>2000){
- $this->imgsize[0]=$this->imgsize[0]*$this->previewsize;
- $this->imgsize[1]=$this->imgsize[1]*$this->previewsize;
- }
- echo("ph_name}" width="{$this->imgsize[0]}" height="{$this->imgsize[1]}">");
- }
- }
- //錯誤提示
- function showerror($errorstr){
- echo "";
- exit();
- }
- function save(){
- $this->check_path();
- $this->check_size();
- $this->check_type();
- $this->up_photo();
- $this->showphoto();
- }
- }
- ?>
http://www.bkjia.com/PHPjc/486216.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486216.htmlTechArticle?php class upphoto{ public $previewsize=0.125 ; //預覽圖片比例 public $preview=0; //是否產生預覽,是為1,否為0 public $datetime; //隨機數 public $ph_name; //上傳...