简体   繁体   中英

How to fix this php file upload issue?

ERROR IN CODE

Notice: Undefined index: filer in C:\\xampp\\htdocs\\nano soft\\programming\\softupload.php on line 6 Notice: Undefined index: filer in C:\\xampp\\htdocs\\nano soft\\programming\\softupload.php on line 7 Notice: Undefined index: filer in C:\\xampp\\htdocs\\nano soft\\programming\\softupload.php on line 8 Notice: Undefined index: filer in C:\\xampp\\htdocs\\nano soft\\programming\\softupload.php on line 9 Notice: Undefined index: filer in C:\\xampp\\htdocs\\nano soft\\programming\\softupload.php on line 10 Notice: Undefined index: filer in C:\\xampp\\htdocs\\nano soft\\programming\\softupload.php on line 11

There was an error uploading software

HTML CODE

<form action="../../programming/softupload.php" method="POST" class="uploader">
    <p class="close">x</p>
    <h3>Upload software</h3>
    <input type="text" class="f1" name="name" placeholder="Software name" required>
    <input class="ch1" type="file" id="file" name="filer" required>
    <label for="file" class="f2">Upload software</label>
    <input class="ch2" type="file" id="file2" name="filer2" required>
    <label for="file2" class="f3">Upload image</label>
    <select name="bitss" class="bitss" required><option value="0" selected="1">Version</option><option value="1">32 [Bit]</option><option value="2">64 [Bit]</option></select>
    <input class="ch3" type="submit" name="submit" value="Upload">
</form>

PHP CODE

<?php
    require_once 'dbh.php';
    if (isset($_POST['submit'])) {
        $getFileName = mysqli_real_escape_string($mysqli, $_POST['name']);
        $getFileNameRel = mysqli_real_escape_string($mysqli, $_POST['bitss']);
        $file = $_FILES['filer'];
        $fileName = $_FILES['filer']['name'];
        $fileTmpName = $_FILES['filer']['tmp_name'];
        $fileSize = $_FILES['filer']['size'];
        $fileError = $_FILES['filer']['error'];
        $fileType = $_FILES['filer']['type'];

        $fileExt = explode('.', $fileName);
        $fileActualExt = strtolower(end($fileExt));
        $uploadDate = date("M d Y");
        $allowed = array("exe", "zip", "msi");
            if (in_array($fileActualExt, $fileExt)) {
                if ($fileError === 0) {
                    if ($fileSize < 2000000000) {
                        $fileNewName = uniqid('', true).".".$fileActualExt;
                        $fileDestination = "software/".$fileNewName;
                        $file1 = $_FILES['filer2'];
                        $fileName1 = $_FILES['filer2']['name'];
                        $fileTmpName1 = $_FILES['filer2']['tmp_name'];
                        $fileSize1 = $_FILES['filer2']['size'];
                        $fileError1 = $_FILES['filer2']['error'];
                        $fileType1 = $_FILES['filer2']['type'];

                        $fileExt1 = explode('.', $fileName1);
                        $fileActualExt1 = strtolower(end($fileExt1));
                        $allowed1 = array("jpeg", "jpg", "png");

                        if (in_array($fileActualExt1, $fileExt1)) {
                            if ($fileError1 === 0) {
                                if ($fileSize1 < 2000000000) {
                                    $fileNewName1 = uniqid('', true).
                                    ".".$fileActualExt1;
                                    $fileDestination1 = "softwares/img/".$fileNewName1;
                                    $sql = "INSERT INTO softwares (name, img, file, bit, uploadDate) VALUES ('$getFileName', '$fileNewName1','$fileNewName', '$getFileNameRel', '$uploadDate')";
                                    $result = mysqli_query($mysqli, $sql);
                                    if ($result == 1) {
                                        move_uploaded_file($fileTmpName, $fileDestination);
                                        move_uploaded_file($fileTmpName1, $fileDestination1);
                                        header("Location: ../includes/the_areas/nanosoft?success=Your software is uploaded successfully!");
                                    } else {
                                        echo "error";
                                    }
                                } else {
                                    echo "Your image is too big";
                                }
                            } else {
                                echo "There was an error uploading image";
                            }
                        } else {
                            echo "You cannot upload image of this type";
                        }
                    } else {
                        echo "Your movie is too big";
                    }
                } else {
                    echo "There was an error uploading software";
                }
            } else {
                echo "You cannot upload this type of software";
            }
    }
?>

添加enctype="multipart/form-data"当您使用具有文件上传控件的表单时,此值是必需的

<form action="../../programming/softupload.php" method="POST" class="uploader" enctype="multipart/form-data">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM