首页 > 代码库 > PHP 上传图片
PHP 上传图片
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<form action="load.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploadFile" id="upload"/> <br/>
<input type="submit" value="http://www.mamicode.com/上传" name="submit"/> <br/>
</form>
</body>
</html>
<?php
if(is_uploaded_file($_FILES[‘uploadFile‘][‘tmp_name‘]))
$file = $_FILES[‘uploadFile‘];
$type = $_FILES[‘uploadFile‘][‘type‘];
$name = $file[‘name‘];
$tmp_name = $file[‘tmp_name‘];
$conn = mysql_connect("localhost","root","") or die("数据库连接失败".mysql_error());
mysql_select_db("bbs");
mysql_query("set names ‘utf8‘");
$sql = "UPDATE `users` SET `userImg`=‘D:/wamp/www/FG19/tempFile/$name‘ WHERE id=1";
$result = mysql_query($sql);
if($result){
move_uploaded_file($tmp_name,"../tempFile/".$name);
}
?>