zoukankan      html  css  js  c++  java
  • PHP文件上传类

    <?php
    /**
     	PHP 多文件上传类
     */
    class Upload{
    
    	//自定义类型
    	private $type;
    
    	//自定义大小
    	private $size;
    
    	//自定义路径
    	private $path;
    
    	//自定义表单name值
    	private $file;
    
    	//源文件临时存储位置
    	private $tmp_name;
    
    	//源文件文件名
    	private $orig_file;
    
    	//源文件大小
    	private $orig_size;
    
    	//源文件类型
    	private $orig_type;
    
    	//上传后新文件名
    	private $new_file;
    
    	//构造方法初始化
    	public function __construct($type, $size, $path, $file){
    
    		$this->type = $type;
    		$this->size = $size;
    		$this->path = $path;
    		$this->file = $file;
    
    	}
    
    	//执行文件上传
    	public function runing(){
    		$count = count($_FILES[$this->file]["name"]);
    		for($i=0; $i<$count; $i++){
    			$this->tmp_name = $_FILES[$this->file]["tmp_name"][$i];
    			$this->orig_file = $_FILES[$this->file]["name"][$i];
    			$this->orig_size = $_FILES[$this->file]["size"][$i];
    			$this->orig_type = strtolower(substr($this->orig_file, strrpos($this->orig_file, ".")+1));
    			$this->new_file = $this->path.date("Y-m-d-H-i-s").rand(0,999).".".$this->orig_type;
    			
    			if($this->checktype()){
    				if($this->checksize()){
    					$this->fileupload();
    
    				}else{
    					echo "<meta charset='utf-8'>该文件大小错误:".$this->orig_file;
    				}
    			}else{
    				echo "<meta charset='utf-8'>该文件类型错误:".$this->orig_file;
    				return false;
    			}
    			
    		}
    	}
    
    	//检查文件的类型
    	private function checktype(){
    		if(in_array($this->orig_type, $this->type)){
    			return true;
    		}else{
    			return false;
    		}
    	}
    
    	//检查文件大小
    	private function checksize(){
    		
    		if($this->orig_size <= $this->size){
    			return true;
    		}else{
    			return false;
    		}
    	}
    
    	//执行上传
    	private function fileupload(){
    		
    		if(is_uploaded_file($this->tmp_name) && isset($_POST["submit"])){
    			$file = move_uploaded_file($this->tmp_name, $this->new_file);
    		}else{
    			return false;
    		}
    		if($file){
    			echo $this->orig_file."<meta charset='utf-8'>上传成功!";
    		}else{
    			echo $this->orig_file."<meta charset='utf-8'>上传失败!";
    		}
    	}
    
    
    }
    
    ?>

      

  • 相关阅读:
    [转]swift 学习资源 大集合
    [转]Swift 编程语言入门教程
    luogu 3375 KMP模板题
    我终于明白了的马拉车算法———感谢我们学校的大佬
    A*B problem(FFT)
    又是毕业季1&&又是毕业季2
    邻接表——最简单易懂的写法——向非我非非我大佬低头
    马拉车——Manacher一篇看上去很靠谱的理解(代码显然易懂)
    邻接表存储
    一直想写的关于tarjan算法的理解——向struct edge大佬低头
  • 原文地址:https://www.cnblogs.com/chenshuo/p/3670103.html
Copyright © 2011-2022 走看看