Home > php教程 > php手册 > php上传文件代码

php上传文件代码

WBOY
Release: 2016-06-06 19:42:26
Original
949 people have browsed it

functionUpload($uploaddir) { $tmp_name =$_FILES['file']['tmp_name']; //文件上传后得临时文件名 $name =$_FILES['file']['name']; // 被上传文件的名称 $size =$_FILES['file']['size']; // 被上传文件的大小 $type =$_FILES['file']['type']; //被上传

 function Upload($uploaddir) 

   

       $tmp_name =$_FILES['file']['tmp_name'];  // 文件上传后得临时文件名 

        $name     =$_FILES['file']['name'];     // 被上传文件的名称 

       $size     =$_FILES['file']['size'];    //  被上传文件的大小 

        $type     =$_FILES['file']['type'];   // 被上传文件的类型 

        $dir      = $uploaddir.date("Ym"); 

        @chmod($dir,0777);//赋予权限 

        @is_dir($dir) or mkdir($dir,0777); 

        //chmod($dir,0777);//赋予权限 

         move_uploaded_file($_FILES['file']['tmp_name'],$dir."/".$name); 

        $type = explode(".",$name); 

        $type = @$type[1]; 

         $date   = date("YmdHis"); 

        $rename = @rename($dir."/".$name,$dir."/".$date.".".$type); 

         if($rename) 

       

         return $dir."/".$date.".".$type; 

        

   

 调用的地方直接用这个: 

 $image = Upload('../images/photo/');就可以了!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template