php上传图片小结

//上传图片很常用,在注册的头像 logo 一般步骤是上传-》修改-》保存等
if(isset($_POST))
{
	if(is_uploaded_file($_FILES['imgfile']['tmp_name']))
	{
		$img = $_FILES['imgfile'];
		$number = rand(100,10000);
		$uploaddir = 'E:\wwwroot\nymsg\html\images\\';
		$uploadfile = $uploaddir .$number. basename($_FILES['imgfile']['name']);
		echo $uploadfile;//把此路径保存到数据库对应的图片字段
		$size = ceil($img['size']/1024);
echo "file size is:".$size."M";
		echo '<pre>';
		if (move_uploaded_file($_FILES['imgfile']['tmp_name'], $uploadfile)) {
		    echo "File is valid, and was successfully uploaded.\n";
		} else {
		    echo "Possible file upload attack!\n";
		}
		
		echo "<img src='".$uploadfile."'>";
		
		print_r($_FILES);
	}
}

 

 

你可能感兴趣的:(html,PHP)