我写这个时有问题:
<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;])) 但是,有人可以帮助我吗?
答案 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>