php图像数据库出错

时间:2015-10-24 20:29:24

标签: php html pdo

我写这个时有问题:

<body>
<form action="new 1.php" method="POST" enctype="multi/form-data">
File:
<input type="file" name="image"><input type="submit" value="upload">

</form>
<?php


$file = $_FILES['image']['tmp_name'];

$dbhost     = "localhost";
$dbname     = "testtest";
$dbuser     = "root";
$dbpass     = "";


$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);


?>

它写给我:未定义的索引:C:\ Program Files(x86)\ EasyPHP-DevServer-14.1VC11 \ data \ localweb \ projects \ guysite2 \ new 1.php中的图像 在第11行

我尝试做:if(isset($ _ FILES [&#39; image&#39;])) 但是,有人可以帮助我吗?

1 个答案:

答案 0 :(得分:3)

替换

<form action="new 1.php" method="POST" enctype="multi/form-data">

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

<强> UPD: 这段代码对我有用:

<?php
    if (isset($_FILES['image'])) {
        $file = $_FILES['image']['tmp_name'];
        echo $file . '<br>';
    }
?>

<form action="new 1.php" method="POST" enctype="multipart/form-data">
    File: <input type="file" name="image">
    <input type="submit" value="upload">
</form>