|
|
萌新提问
平常提交表单都是isset检测一下submit有没有值
但是今天实操图片上传
教程里用的也是 isset($_POST['submit']) 检测到了值然后一系列图片操作 入库路径等
但是我自己写的提没提都显示的是true
搜了一下网上别人的例子 好像都是检测 $_FILES
像这种
$image = $_FILES['image'];
$image['error'] > 0)
所以提问一下 是不是html from表单改成file post就检测不到了
下方为我写的代码
不管是点post提交 还是图片已经上传了$file有东西 都走的else那条线
html部分
<div id="main">
<h2>更改头像</h2>
<div>
<h3>原头像:</h3>
<img src="<?php if($photo['photo']!=''){echo $photo['photo'];}else{echo '/index/style/photo.jpg';}?>" />
</div>
<div style="margin:15px 0 0 0;">
<form action="member_photo_update.php" method="post" enctype="multipart/form-data">
<input style="cursor:pointer;" width="100" type="file" name="file"/><br /><br />
<input class="submit" type="submit" value="保存" />
</form>
</div>
</div>
php部分
<?php
//引入数据库配置文件
include_once 'inc/config.inc.php';
//引入数据库操作文件
include_once 'inc/mysql.inc.php';
session_start();
if(!isset($_SESSION['name'])){
echo "未登录,请登陆后在发帖";
// 3秒后跳转到父板块
header("refresh:3;url=./login.php");
exit;
}
if(isset($_POST['submit'])){
var_dump($_FILES);
echo "提交了";
exit;
// $type=array("image/jpeg","image/jpg","image/pjpeg");
// if(!in_array($_FILES['file']['type'],$type)){
// echo "不支持的文件格式";
// // 3秒后跳转到父板块
// header("refresh:3;url=./member_photo_update.php");
// exit;
// }
}else{
$link=connect();
$query="select * from sfk_member where id={$_SESSION['member_id']}";
$res=execute($link,$query);
$photo=mysqli_fetch_assoc($res);
//引入头部模板
include_once 'index/inc/header.html';
//引入主体模板
include_once 'index/inc/member_photo_update.html';
//引入尾部模板
include_once 'index/inc/footer.html';
} |
|