全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1102|回复: 6

[Windows VPS] php isset($_POST['submit']) 问题 萌新提问

[复制链接]
发表于 2019-9-2 22:10:24 | 显示全部楼层 |阅读模式
萌新提问
平常提交表单都是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';
}
发表于 2019-9-2 22:27:43 来自手机 | 显示全部楼层
isset一般还要加个额外条件检测下是否有值
发表于 2019-9-2 22:32:51 | 显示全部楼层
楼主要问的应该是$_FILES这个
检测submit不靠谱
建议使用empty($_FILES)检测
 楼主| 发表于 2019-9-2 22:57:37 | 显示全部楼层
Eric.c 发表于 2019-9-2 22:27
isset一般还要加个额外条件检测下是否有值

谢谢呀
我是上传图片 准备用submit检测有没有提交
怎么都不成
最后测试了一下发现 $post没有任何数据 只有file有数据
 楼主| 发表于 2019-9-2 22:59:11 | 显示全部楼层
雨灵 发表于 2019-9-2 22:32
楼主要问的应该是$_FILES这个
检测submit不靠谱
建议使用empty($_FILES)检测


谢谢呀

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

发表于 2019-9-3 09:53:54 | 显示全部楼层
<input class="submit" type="submit" value="保存" />
没有name 这个value不会post过去的
 楼主| 发表于 2019-9-3 16:19:43 | 显示全部楼层
萧金 发表于 2019-9-3 09:53
没有name 这个value不会post过去的

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

谢谢大佬
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-24 01:20 , Processed in 0.068002 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表