我尝试更多上传图片,但是即使我尝试更多,它也会出现错误

时间:2018-09-08 10:34:12

标签: php html css

有人可以帮我上传图像时遇到问题吗?

PHP

<?php
    $msg="";
    $db=mysqli_connect("localhost","root","root","man");
    if(isset($_POST['submit'])) {
        $fileName=$_FILES['uploadfile']['name'];
        $fileTmpName=$_FILES['uploadfile']['tmp_name'];
        $folder='images/';
        move_uploaded_file($fileTmpName,$folder.$fileName);

        $sql=mysqli_query($db,"INSERT INTO manimages(image) VALUES ($fileName)");
   }
?>

HTML

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Uploading Images</title>
    </head>
    <body>
        <form action="" method="POST">
            <input type="file" name="uploadfile">
            <input type="submit" name="submit" value="upload image">
        </form>
   </body>
</html>

错误提示:未定义索引:第5行C:\ wamp64 \ www \ ftest \ index.php中的uploadfile 和注意:未定义的索引:在第6行的C:\ wamp64 \ www \ ftest \ index.php中上传文件

2 个答案:

答案 0 :(得分:1)

要允许表单上传文件,您应指定正确的job属性,默认情况下为$('#content *').each(function(_, el) { el.getAttributeNames().forEach(el.removeAttribute.bind(el)); }); console.log($('#content')[0].outerHTML),应将其更改为<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="content"> <span id="span" data-span="a" aria-describedby="span">span</span> <p class="a b c" style="color:black;">paragraph</p> </div>

尝试一下:

enctype

现在您可以访问application/x-www-form-urlencoded超全局变量multipart/form-data,因此不会引发未定义的索引错误。

答案 1 :(得分:0)

您的form标签不完整,用于上传图像的外观应为:

<form action="" method="post" enctype="multipart/form-data">

请记住,如果您正在使用文件上传控件,则必须将enctype设置为multipart/form-data