我如何从我的HTML表单,我的PHP脚本的选择期权的价值?

问题描述 投票:-1回答:1

我正在为我的网站,我希望用户能够上传DXF文件和有关材料到我的网站服务器的某些信息的形式。

现在我可以将文件上传到服务器。但由于某些原因,我不能让PHP脚本从选择的选项,我也有形式读出值。

我认为问题是,PHP脚本不到风度知道去哪里找的价值观,因为当我提交表单,我得到Notice: Undefined index:

我一直在使用if(isset()),看看是否有其实是一个值,以节省审理。我也曾尝试启动,我要保存价值的变量,但没有任何工程。

我是超级新HTML和PHP,我只用它工作了两天,所以它可能不会停超级简单的我失踪。

这是HTML格式使用:

<form action = "../php/uploadDXF.php" method = "POST" enctype="multipart/form-data">

    <!-- Selector for differnet materials -->
    <select id = "material"> 
        <option value="0" >- Selecet material -</option>
        <option value="1" >Stainless steel</option>
        <option value="2" >Hot rolled</option>
        <option value="3" >Cold rolled</option>
        <option value="4" >Aluminium</option>
    </select>

    <!-- Selector for material thicknesses, see selector.js -->
    <select id = "thickness"> 
        <option value="0" >- Selecet thickness -</option>
    </select>
    <!-- Form for uploading a .DXF file, see uploadDXF.php -->
    <input type = "file" name = "inputDXF"/>
    <button type = 'submit' name = 'submit'>Upload</button>

</form>

这是我的PHP脚本:

<?php
// php script for uploading a file to the webserver via the website. 

//Variables
$maxFileSize = 10000; 
$selectedMaterial = 'test1';
$selectedThickness = 'test2';

if(isset($_POST['submit'])) { // Run this program when Upload is clicked


    // Material and thickness
    if(isset($_POST['material'])) { 

    }
    if(isset($_POST['thickness'])) {

    }
    $selectedMaterial = $_POST['material']['value'];
    $selectedThickness = $_POST['thickness']['value'];

$file = $_FILES['inputDXF']; // The file being uploded

    // Name, size, location, error and type of file being uploaded
    $fileName = $_FILES['inputDXF']['name']; 
    $fileSize = $_FILES['inputDXF']['size'];
    $fileTmpName = $_FILES['inputDXF']['tmp_name'];
    $fileError = $_FILES['inputDXF']['error'];
    $fileType = $_FILES['inputDXF']['type'];
    // ---------------------------------------------

    $fileExt = explode('.', $fileName); // Explode name in to array
    $fileActualExt = strtolower(end($fileExt)); // Make last entry in array lowercase 

    $allowedFileTypes = array('dxf'); // Files that are allowed to be uploaded

    if (in_array($fileActualExt, $allowedFileTypes)) { // Is the file-type allowed?

        if($fileError === 0) { // Is the file free of errors?

            if ($fileSize < $maxFileSize) { // Is the file too big?

                $fileNameNew = uniqid('', true).".".$fileActualExt; // Gives the uploaded file a uniqe name
                $fileDestionation = '../uploads/'.$fileNameNew; // Where the file should be uploaded
                move_uploaded_file($fileTmpName, $fileDestionation); // Function that uploads the file


            } else {
                echo "Your file is too big. Maximum size allowed: 10mb.";
            }
        } else {
            echo "There was an error uploading your file.";
        }
    } else {
        echo "The file must ba a .DXF";
    }

}
echo $selectedMaterial;
//header("Location: http://localhost/Version%203/pages/test.html");
?>

我知道你不应该包括完整的PHP脚本,但我不确定什么是重要的。

我所试图做的是呼应保存变量$selectedMaterial$selectedThickness的价值在PHP脚本的末尾,看看它是否工作。但是,他们永远不会改变什么,我选择了在选择选项。

请帮忙!

php html
1个回答
3
投票

表单元素所需要的name属性$_POST阵列中显示出来:

<form action = "../php/uploadDXF.php" method = "POST" enctype="multipart/form-data">

    <!-- Selector for differnet materials -->
    <select id = "material" name="material"> 
        <option value="0" >- Selecet material -</option>
        <option value="1" >Stainless steel</option>
        <option value="2" >Hot rolled</option>
        <option value="3" >Cold rolled</option>
        <option value="4" >Aluminium</option>
    </select>

    <!-- Selector for material thicknesses, see selector.js -->
    <select id = "thickness" name="thickness"> 
        <option value="0" >- Selecet thickness -</option>
    </select>
    <!-- Form for uploading a .DXF file, see uploadDXF.php -->
    <input type = "file" name = "inputDXF"/>
    <button type = 'submit' name = 'submit'>Upload</button>

</form>
© www.soinside.com 2019 - 2024. All rights reserved.