Home > php教程 > PHP源码 > body text

php上传图片

PHP中文网
Release: 2016-05-25 17:12:52
Original
1031 people have browsed it

代码

function Upload($file_name,$path,$pub,$size=204800)
{

//function Upload($file_name,$path,$pub){


	$type        = implode(",",$pub);

	$root        = $_SERVER['DOCUMENT_ROOT'];                //查找站点根路径

	$image       = $_FILES[$file_name];                      //接收文件域的值(一个数组)

	if($image['name']=="")

	{

		return "";

	}

	$upload_path = $root.$path;                              //设置上传文件位置

	$leixing     = strtolower(strrchr($image['name'],"."));  //把上传的文件名“.”以后的部分全部小写(取得文件的扩展名)

	$suijishu    = rand(100,999);                            //取一个100--999的随机数;

	$server_file = time().$suijishu.$leixing;                //取得上传文件名(时间戳加随机数加扩展名)

	if (in_array($leixing,$pub))

	{     

		//判断扩展名,(设置上传类型)

		/*

		 if ($image['size'] > $size){                            //比较上传文件大小和甚至的大小

			echo "";

			exit;

		 }

		 */

		$wenjia = 0;               

		 if (file_exists($upload_path.$server_file) && !$wenjia){  //判断文件名是否存在

			echo "";

			exit; 

		 }

		 if (!move_uploaded_file($image['tmp_name'],$upload_path.$server_file)){//上传文件

			echo "";

			exit; 

		 }

	}else{

		echo "";

		exit; 

	}

	return  $server_file;                 //返回文件名(含路径)

}
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!