Home >php教程 >PHP源码 >php文件上传类

php文件上传类

PHP中文网
PHP中文网Original
2016-05-25 17:14:24976browse


	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:SQL语句解析函数Next article:php页面执行时间