php - 通知 : Undefined index: image in

标签 php database upload xampp

<分区>

Possible Duplicate:
Undefined index: file

你好,我正在学习如何将图像上传到数据库,但是我收到了这个错误/通知

Notice: Undefined index: image in C:\xampp\htdocs\Pildibaas\index.php on line 19

这是我的 index.php 的全部代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Image upload</title>
</head>

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


<?php
mysql_connect ("localhost", "root", "") or die (mysql_error());
mysql_select_db ("databaseimage") or die (mysql_error());


?>
</body>

</html>

从 index.php 中截取的第 19 行(此行出错):

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

从谷歌发现我需要更改 tmp 文件夹的权限,但它应该已经具备了它需要的所有权限。

在教程中他没有得到这个错误

谢谢

最佳答案

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

应该是

if(isset($_FILES['image'])){
    echo $_FILES['image']['tmp_name'];
}

这首先检查是否设置了 $_FILES['image']。如果不是,则不会运行。因此,您不会有它超出索引的错误。

因为您首先必须在设置 $_FILES['image'] 之前提交表单...

此外,输入标签是自关闭的,因此您的表单不会:

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

但是:

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

关于php - 通知 : Undefined index: image in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13108901/

相关文章:

java - 如何进行数据库查询的 JUNIT 测试

php - 更新数据库表格 : leaves image fields blank when no file is selected

php - 类别的嵌套函数

php - 制作没有 ID 的 SEO 友好 URL

database - 何时从电子表格切换到 RDBMS?

java - 数据库中的用户名未显示在网页中?

Arduino 莱昂纳多 - "avrdude: butterfly_recv(): programmer is not responding"

ruby-on-rails - 在 Rails 中处理多个文件上传的最佳插件是什么?

php 数据未处理,有人可以查看我的代码吗?

php - 表格显示问题;尴尬的行显示