PHP $ _FILES仅包含名称的超全局

时间:2013-12-24 16:58:09

标签: php file-upload

我已经查了全部,包括以下链接:
http://getluky.net/2004/10/04/apachephp-_files-array-mysteriously-empty/
PHP upload file - only $_FILES['name'] is populating
等并尝试了所有的建议但无济于事。 我甚至去了var_dumping $ _POST和$ _FILES的范围:

array(1) { 'description' => string(11) "finaldemand" }

array(1) {
  'file' =>
  array(5) {
    'name' =>
    string(16) "finaldemand.docx"
    'type' =>
    string(0) ""
    'tmp_name' =>
    string(0) ""
    'error' =>
    int(6)
    'size' =>
    int(0)
  }
}

看起来文件根本没有被提交,虽然我的HTML(我尝试了其他各种)似乎是正确的:

    <form enctype="multipart/form-data" action="addTemplateScript.php" method="POST">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td>Choose a file to upload:</td>
                    <td>
                        <input type="file" name="file" id="file">
                    </td>
                </tr>
                <tr>
                    <td>Used as:</td>
                    <td>
                        <input type="radio" name="description" id="transfer" value="transfer" />Application to Transfer<br />
                        <input type="radio" name="description" id="lay" value="lay" />Application to Lay a Mooring<br />           
                    </td>
                <tr>
                    <td><input type="submit" value="Upload file">
                </tr>
            </table>
        </form>

此脚本检查它是否是.docx并将所有数据放入变量(包括PDO在内的一点太大,所以我修剪了它):

<?php
include("includes/session.php");
var_dump($_POST);
// Check if a file has been uploaded
if (isset($_FILES['file'])) {
    echo "<pre>";var_dump($_FILES);echo "</pre>";
        // Connect to the database
        $database = $functions->pdoConnect();

        // Gather all required data
        $name = $_FILES['file']['name'];
        $mime = $_FILES['file']['type'];
        $data = file_get_contents($_FILES  ['file']['tmp_name']);
        $size = intval($_FILES['file']['size']);
        $description = $_POST['description'];
        if ($mime != "application/vnd.openxmlformats-officedocument.wordprocessingml.document") {
            die("The file was not a .docx! Upload was cancelled.");
        }

有什么东西可能会干扰吗?我应该注意一个错误吗? **编辑:** 我正在运行PHP 5.5.6如果有帮助

2 个答案:

答案 0 :(得分:2)

你有:

$_FILES['file']['error'] = 6;

这意味着:UPLOAD_ERR_NO_TMP_DIR。检查你的tmp目录是否存在,并且用户可以从中运行php。

答案 1 :(得分:-2)

@Greshnik

不太......

$_FILES['file']['error'] = int(6); // This has a NULL value.

int(6)不是值,而是数据格式,如......

$_FILES['file']['name'] = string(16) "finaldemand.docx"; // See value in quotes at end

$_FILES['file']['type'] = string(0) ""; // Value again in quotes

$_FILES['file']['tmp_name'] = string(0) ""; // Value again in quotes

$_FILES['file']['size'] = int(0); // Another one with a NULL value