php:
<?php include 'header1.php'; ?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>相册管理页面</title>
<link rel="stylesheet" href="css/xcgl_set.css" />
<link rel="stylesheet" href="css/xcgl.css">
<style>
*{ font-family:微软雅黑}
</style>
</head>
<?php
//1.创建数据库
$con = mysql_connect("localhost","root","root");
//2.验证
if($con){
//echo "数据库连接成功<br/>";
}else{
echo "数据库连接失败<br/>";
}
//3.指定数据库
mysql_select_db("sgjydb",$con);
//4.读取数据
mysql_query("set names utf8");//指定字符编码
$query = "select * from imgclasstab";
$result = mysql_query($query);
if($result){
//echo "查找数据成功<br/>";
}else{
echo "查找数据失败<br/>".mysql_errno();
}
?>
<body>
<!-- works -->
<div id="works" class=" clearfix grid">
<?php
while ($list = mysql_fetch_array($result)){
//echo "id=".$list["imgClassId"];
$imgClassId = 1;
echo '<figure class="effect-oscar wowload fadeIn">';
echo '<img src="'.$list["imgClassCoverUrl"].'" alt="img01"/>';
//echo "当前的图地址:".$list["imgClassCoverUrl"];
//$tjquery = "select imgClassId,imgClassDescription from imgclasstab where imgClassCoverUrl=".$list["imgClassCoverUrl"];
//$tjresult = mysql_query($tjquery);
//$tjId = $list["imgClassId"];
echo '<figcaption>';
echo '<h2>'.$list["imgClassCName"].'</h2>';
echo '<p>'.$list["imgClassDescription"].'<br>';
echo '<a href="xcgl_ny.php?id='.$list["imgClassId"].'" title="1" data-gallery>查看更多</a></p>';
echo '</figcaption>';
echo '</figure>';
}
?>
</div>
<!-- works -->
<!-- 创建相册 -->
<!-- 创建相册结束 -->
<div data-toggle="modal" data-target="#myModal" style="background:red; position:fixed; bottom:0; right:0; width:50px; height:50px; z-index:22222; background:url(images/addXc.png); background-size:cover;"></div>
<!-- 模态框(Modal):创建相册 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="background:#eee">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
<img src="images/addXc.png" width="5%" height="5%"> 创建相册
</h4>
</div>
<div class="modal-body">
<form action="" method="post" name="addClassForm" id="addClassForm" role="form">
<div class="form-group">
<label>相册封面图:</label>
<input type="file" id="classCover" name="classCover" class="form-control">
</div>
<div class="form-group">
<label>相册名称:</label>
<input type="text" id="className" name="className" class="form-control">
</div>
<div class="form-group">
<label>相册描述:</label>
<input type="textarea" id="classDesciription" name="classDesciription" class="form-control" placeholder="说说这个相册的故事呗...">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-xs btn-default btn-toolbar" data-dismiss="modal" style="width:20%;">取消
</button>
<input type="submit" class="btn btn-xs btn-primary" id="addXcBtn" name="addXcBtn" value="确定" style="width:20%;">
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>
<!-- 模态框(Modal) -->
<script src="js/bootstrap.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#addXcBtn").click(function(){
alert("开始创建");
$.ajax({
url:'php/addXc.php',
type:'post',
data:{//键值对中:前者键是input的name键值,后者值为input的value值
"addXcBtn":$("#addXcBtn").val(),
"classCover":$("#classCover").attr("name"),
//"classCover":$("#classCover").val(),
"className":$("#className").val(),
"classDesciription":$("#classDesciription").val(),
},
success:function(data){
console.log("data="+data);
if(data=="创建成功"){
alert("创建成功");
}else{
alert("创建失败");
}
}
})
});
});
</script>
</body>
</html>
php:
<?php
$bb = 'begin';
$xcCover = $_POST["classCover"];
/*echo "相册封面:".$xcCover."<br/>";
$aa = $_FILES["'".$xcCover."'"]['name'];
echo "相册封面名称:".$aa."<br/>";*/
$aa = $_FILES["'".$xcCover."'"]['type'];
echo "相册封面类型:".$aa."<br/>";
$scName = $_POST["className"];
echo "相册名称:".$scName."<br/>";
$xcDes = $_POST["classDesciription"];
echo "相册描述:".$xcDes."<br/>";
/*$addXcBtn = $_POST["addXcBtn"];
echo "获取到相册封面的name是:".$addXcBtn."<br/>";
$xcCover = $_POST["classCover"];
echo "获取到相册封面的name是:".$xcCover."<br/>";
*/
/*$aa = 'ww';
if($aa == 'w'){
echo "创建成功";
}else{
echo "创建失败";
}
$aa = 'begin';
$addXcBtn = $_POST["addXcBtn"];
echo "获取的提交按钮的value是:".$addXcBtn."<br/>";
$xcCover = $_POST["classCover"];
echo "封面value是:".$xcCoverName;
$xcCoverName = $_FILES["'".$xcCover."'"]['name'];
echo "封面名称是:".$xcCoverName;
*/
if($bb == 'w'){
echo "创建成功";
}else{
echo "创建失败";
}
?>
我看你的form好像没写 enctype="multipart/data-form"这个属性