无法同时从一种表单提交文本输入和文件输入

时间:2018-10-11 18:00:39

标签: php html

我上载带有文件输入的文件没有问题,但是文本输入甚至不响应我的点击。我尝试删除文件输入,然后它们又开始运行。有什么办法可以同时使用一种形式?

    <form class="upload-box-content popup-animation" action="uploadproject.php"
    method="POST" enctype="multipart/form-data">
        <div class="text-block">
            <input type="text" name="project-name" placeholder="Название проекта">
            <input type="text" name="authors" placeholder="Автор(ы) проекта">
            <input type="text" name="supervisor" placeholder="Куратор проекта">
            <input type="text" name="faculty" placeholder="Кафедра">
        </div>

        <div class="upload-tp-block">
            <input type="file" name="textfile">
            <input type="file" name="ppfile">
        </div>
        <button type="submit" name="submit">Загрузить</button>
    </form>

这是uploadproject.php代码。我必须说,我现在不使用来自文本输入的数据(毕竟甚至不能输入任何东西)。

<?php
if (isset($_POST['submit'])) {
    //Getting file and all file variables
    $textfile = $_FILES['textfile'];
    $textfilename = $_FILES['textfile']['name'];
    $textfileTmpName = $_FILES['textfile']['tmp_name']; 
    $textfileSize = $_FILES['textfile']['size'];
    $textfileType = $_FILES['textfile']['type'];
    $textfileError = $_FILES['textfile']['error'];

    $ppfile = $_FILES['ppfile'];
    $ppfilename = $_FILES['ppfile']['name'];
    $ppfileTmpName = $_FILES['ppfile']['tmp_name']; 
    $ppfileSize = $_FILES['ppfile']['size'];
    $ppfileType = $_FILES['ppfile']['type'];
    $ppfileError = $_FILES['ppfile']['error'];
    //Getting file extensions
    $textfileExt = explode('.', $textfilename);
    $ppfileExt = explode('.', $ppfilename);
    //Make it lowercase so JPG turn into jpg, and get the extension itself
    $textfileActualExt = strtolower(end($textfileExt));
    $ppfileActualExt = strtolower(end($ppfileExt));

    //Allowed extensions
    $textallowed = array('docx', 'doc', 'txt', 'text', 'pdf');
    $ppallowed = array('ppt', 'pptx');

    if (in_array($textfileActualExt, $textallowed) && 
        in_array($ppfileActualExt, $ppallowed)) {
        if ($textfileError === 0 && $ppfileError === 0) {
            if ($textfileSize < 20000000 && $ppfileSize < 20000000) {
                $textfileDestination = 'uploads/'.$textfilename;
                $ppfileDestination = 'uploads/'.$ppfilename;
                move_uploaded_file($textfileTmpName, $textfileDestination);
                move_uploaded_file($ppfileTmpName, $ppfileDestination);
                header("Location: main.php?upload=success");    
            }
        } else {
            echo "Couldn't upload your file".$textfileError.$ppfileError;
        }
    } else {
        echo "Wrong extension boi";
    }

}


?>

1 个答案:

答案 0 :(得分:-1)

显然有一些div问题。毕竟是CSS。感谢您的合作。