Home  >  Article  >  php教程  >  php upload file code

php upload file code

大家讲道理
大家讲道理Original
2016-11-08 14:38:301349browse

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/');就可以了!

Statement:
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
Previous article:php smtp send emailNext article:php smtp send email