<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js">
</script>
<script src="./aa.js"></script>
<form method="post" action="" enctype="multipart/form-data" id="form">
<input type="file" name="file" onchange="aj()" id="bnm">
<input type="submit" name="zxing">
<img src="https://img2.baidu.com/it/u=1171791560,3850385956&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
alt="" id="a">
</form>
<?php
// 连接
$servername = "localhost";
$username = "root";
$password = "123456";
$dbname = "myDB";
$conn = new mysqli($servername, $username, $password,$dbname);
// 检测连接
if ($conn->connect_error) {
echo "<script>alert('小皮是不是没有开?')</script>";
}
// 允许上传的图片后缀
$a = array("gif", "jpeg", "jpg", "png");
// 分解后缀
$b = explode(".", $_FILES["file"]["name"]);
// 获取文件后缀名
$c = end($b);
$name = '二';
$passwordss = '123456';
// $f = $_POST['file'];
// $file = $_POST['file'];
// 插入
if (array_key_exists('zxing',$_POST)) {
$d = "upload/" . $_FILES["file"]["name"];
// copy($file,$_FILES["files"]);
echo "<br/>";
echo $f;
echo "<br/>";
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 204800) // 小于 200 kb
&& in_array($c, $a))
{
if ($_FILES["file"]["error"] > 0)
{
echo "66666";
}
else
{
// 判断上传的东西存不存在
if (file_exists($d))
{
echo 1;
}
else
{
// 如果 upload 目录不存在该文件则将文件上传到 upload 目录下
move_uploaded_file($_FILES["file"]["tmp_name"], $d);
echo "名字".$_FILES["file"]["name"];
echo "<br/>";
echo "类型".$_FILES["file"]["type"];
echo "<br/>";
echo "大小".$_FILES["file"]["size"];
echo "<br/>";
echo "位置".$_FILES["file"]["tmp_name"];
echo "<br/>";
$fc = "./upload/" .$_FILES["file"]["name"];
echo $fc;
$sqls = "INSERT INTO wangmou (name, password,img)VALUES('$name','$passwordss','$fc')";
if ($conn->query($sqls) === TRUE) {
echo "<center> 插入成功!</center>";
}else{
// echo "失败";
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
}
}
else
{
echo 2;
}
}
?>