全球主机交流论坛

标题: php isset($_POST['submit']) 问题 萌新提问 [打印本页]

作者: 很单纯的小伙子    时间: 2019-9-2 22:10
标题: php isset($_POST['submit']) 问题 萌新提问
萌新提问
平常提交表单都是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';
}
作者: Eric.c    时间: 2019-9-2 22:27
isset一般还要加个额外条件检测下是否有值
作者: 雨灵    时间: 2019-9-2 22:32
楼主要问的应该是$_FILES这个
检测submit不靠谱
建议使用empty($_FILES)检测
作者: 很单纯的小伙子    时间: 2019-9-2 22:57
Eric.c 发表于 2019-9-2 22:27
isset一般还要加个额外条件检测下是否有值

谢谢呀
我是上传图片 准备用submit检测有没有提交
怎么都不成
最后测试了一下发现 $post没有任何数据 只有file有数据

作者: 很单纯的小伙子    时间: 2019-9-2 22:59
雨灵 发表于 2019-9-2 22:32
楼主要问的应该是$_FILES这个
检测submit不靠谱
建议使用empty($_FILES)检测


谢谢呀

我是上传图片 准备用submit检测有没有提交
怎么都不成
最后测试了一下发现 $post没有任何数据 只有file有数据


作者: 萧金    时间: 2019-9-3 09:53
<input class="submit" type="submit" value="保存" />
没有name 这个value不会post过去的
作者: 很单纯的小伙子    时间: 2019-9-3 16:19
萧金 发表于 2019-9-3 09:53
没有name 这个value不会post过去的

大佬 解决了我的疑惑啊
我就说我post怎么检测不到
是自己粗心了

谢谢大佬




欢迎光临 全球主机交流论坛 (https://443502.xyz/) Powered by Discuz! X3.4