【问题标题】:How get type or id data sent post? [closed]如何获取发送的类型或 id 数据? [关闭]
【发布时间】:2015-12-13 19:55:32
【问题描述】:

我有这个发送日期的代码:

<form enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
    <input name="file[]" type="file" id="img">
    <textarea name="file[]" rows="5" cols="50" id="textarea"></textarea>
    <input name="file[]" type="text" id="text" value="">
    <input type="submit" value="upload" name="submit" id="upload" class="upload"/>
</form>

还有这段代码:

<?php
    if (isset($_POST['submit'])){
        $textarea=$_POST['file'];
        $implodetextarea=implode(",",$textarea);
        for ($i = 0; $i < count($textarea); i++){
            echo $textarea['id'][$i];//This is wrong 
        }
    }
?>

现在如何获取数据的类型以及如何区分图片或文字,或其他?

【问题讨论】:

  • 文件将在$_FILES 超全局中,其他所有内容都在$_POST

标签: javascript php jquery html forms


【解决方案1】:

Windows 中的数据验证基于荣誉系统 - 文件的后缀(.txt、.jpg、.zip 等)告诉系统文件中的数据类型。当然后缀可以改变,所以它不是一个完美的系统。在其他操作系统中,文件后缀不太普遍,并且在需要时必须通过检查文件的内容来完成数据验证。例如,如果您希望用户上传 jpg,您可以使用 PHP 的 fopen 和 fread 在上传的文件中搜索 jpg 标头。简而言之,如果不打开文件并阅读内容,您将无法确定上传的是哪种文件。

【讨论】:

  • mime 类型由浏览器确定,用于填充 $_FILES 数组
【解决方案2】:

您可以查找文件的 mime 类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 2014-12-11
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    • 2010-09-11
    • 1970-01-01
    相关资源
    最近更新 更多