为什么我不能在php中更改输入文件名?

时间:2017-02-21 08:54:56

标签: php html global-variables

当我运行以下代码时,它说

  

“注意:未定义的索引:第17行的C:\ xampp \ htdocs \ ImageTest \ processImage.php中的uploadFile”

但是当我用uploadToUpload替换uploadFile的每个实例时,它似乎工作。为什么呢?

processImage.php

<!DOCTYPE html>
<html>
<head>
    <title> hello world</title>
</head
<body>
    <?php
        echo ' hi';

        $servername="localhost";
        $username="root";
        $password="";
        $dbname="db_ImageTest";

        $conn=new mysqli($servername, $username, $password, $dbname);

        echo $_FILES["uploadFile"]["name"];

        /*
        echo $image;

        $image_name=$_FILES['image']['name'];
        $image_size=getimagesize($_FILES['image']['tmp_name']);

        if($image_size==FALSE){
            echo 'failed';
        }
        $query="INSERT INTO mytable(image, name) VALUES(' {$image}',  '{$image_name}') 
        */
    ?>
</body>
</html>

的index.php

<!DOCTYPE html>
<html>
<body>

<form action="processImage.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="uploadFile" />
    <input type="submit" value="Upload Image" name="submit"/>
</form>

</body>
</html>

1 个答案:

答案 0 :(得分:2)

&#34;注意:未定义的索引:第17行&#34的C:\ xampp \ htdocs \ ImageTest \ processImage.php中的uploadFile;

这意味着没有发送文件,您可以使用isset检查文件是否已附加,否则会发出通知:

if (isset($_FILES['uploadFile'])) {
    /** file is there, continue your uploading **/
   }