【问题标题】:php - upload csv file not being stored to $_FILESphp - 上传未存储到 $_FILES 的 csv 文件
【发布时间】:2014-01-18 02:36:13
【问题描述】:

我有这个基本的上传代码:

<form action="upload.php" method="post" >
<input type="file" name="file" value="" />
<input type="submit" name="submit" value="Go" />
</form>

<?php
if(isset($_POST['submit'])){
    echo '<h3>Post test: </h3>';
    var_dump($_POST);
    $csv = array();

    if(isset($_FILES["file"])) {
        //if there was an error uploading the file
        if($_FILES["file"]["error"] > 0) {
            echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        }
        else {
            //Print file details
            echo "Upload: " . $_FILES["file"]["name"] . "<br />";
            echo "Type: " . $_FILES["file"]["type"] . "<br />";
            echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
            echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
        }
    }
    else {
        echo "No file selected <br />";
    }
}

我不断收到“未选择文件”,这是 isset($_FILES['file'] 的 else 后备。

我的 php.ini 文件中是否需要设置某些内容以允许我将文件上传到临时位置?除了提交表单以将文件设置为$_FILES之外,我还需要做些什么吗?

【问题讨论】:

    标签: php html file-upload


    【解决方案1】:

    您在表单标签中缺少enctype="multipart/form-data" 属性:

    <form action="upload.php" method="post" enctype="multipart/form-data">
    

    【讨论】:

    • sigh 它始终是 enctype。
    • 完美。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-11
    • 2011-11-19
    • 2017-12-12
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    相关资源
    最近更新 更多