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

php文件上传类

PHP中文网
Release: 2016-05-25 17:14:24
Original
956 people have browsed it


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

                   

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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template