Heim  >  Artikel  >  Backend-Entwicklung  >  php上传文件类_PHP教程

php上传文件类_PHP教程

WBOY
WBOYOriginal
2016-07-14 10:07:24773Durchsuche

[php] 
header("Content-Type:text/html; charset=utf-8;"); 
echo "uploadclass
"; 
echo "
".$_FILES['file']["name"]."
"; 
 
$nabc = new uploadclass($_FILES['file']);  
echo "
".$nabc->getname()."
";//获取新的名字 
 
 
class uploadclass { 
    var $location ;//设置存放文件的目录 
    var $max_size;//上传文件的大小 
    var $event; //初始值是success 
    var $filename;//获取保存在文件夹里的文件的文件名字 
    function uploadclass($file) { 
        $location = "./temp/";//设置存放文件的目录 
        $max_size = 1000000;//上传文件的大小 
        $event="success"; //初始值是success 
        //判断目录是否存在 
        if(! is_dir($location)) 
         {  
              mkdir($location); 
              @chmod($location,777); 
         } 
          
        $oldFilename = $file["name"]; 
        $filename = explode(".",$oldFilename); 
        $filenameext = $filename[count($filename) - 1]; 
        $newFilename = "_".time()."_".rand(10000, 20000).".".$filenameext; 
        $this->filename = $newFilename; 
         
        echo "
".$this->$filename."
"; 
        if(!$file['name']=="") 
        {  
            if($file['size']             {  
                echo "文件上传路径:".$location.$file['name'];  
                move_uploaded_file($file['tmp_name'], $location.$newFilename) or $event = "Failure";  
            }  
            else 
            {  
                $event="File too large";  
            }  
        }  
    } 
     
    public function getname() 
      { 
        return  $this->filename; 
      } 

?> 

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477877.htmlTechArticle[php] ?php header(Content-Type:text/html; charset=utf-8;); echo uploadclassbr/; echo br/.$_FILES[file][name].br/; $nabc = new uploadclass($_FILES[file]); echo br/.$nabc-getname().b...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn