无法使用$ _FILES方法PHP访问文件名

时间:2015-01-21 07:51:40

标签: php

我正在尝试构建一个文件上传器,其中包含一个不会覆盖文件的youtube教程,现在我仍然坚持使用该名称。使用$ _Files什么都不返回,我不确定为什么。 :/

我试图回应它,但没有回来。

其他一切似乎都有效。

<html>
<head>
</head>
<body>
<?php

error_reporting(-1);
ini_set('display_errors', 'On');

$con = mysql_connect("localhost","root","root");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("example",$con);

if(isset($_POST['update'])){
$UpdateQuery = "UPDATE repo SET location='$_POST[location]', name='$_POST[name]', description='$_POST[description]' WHERE location='$_POST[hidden]'";               
mysql_query($UpdateQuery, $con);
};

if(isset($_POST['delete'])){
$DeleteQuery = "DELETE FROM repo WHERE location='$_POST[hidden]'";          
mysql_query($DeleteQuery, $con);
};

if(isset($_POST['add'])){

$AddQuery = "INSERT INTO repo (name, id, image, location, partners, description, date) VALUES ('$image_name', '','$_POST[uimage]', '$_POST[ulocation]', '$_POST[upartners]', '$_POST[udescription]', NOW())";         
mysql_query($AddQuery, $con);
};



$sql = "SELECT * FROM repo";
$myData = mysql_query($sql,$con);
echo "<table border=1>
<tr>
<th>Image</th>
<th>Name</th>
<th>Location</th>
<th>Partners</th>
<th>Description</th>
<th>Date</th>
</tr>";
while($record = mysql_fetch_array($myData)){
    ?>
<form action="mydata5.php"
method="post" enctype="multipart/form-data">

<?php
echo "<tr>";

echo "<td>" . "<img src=Assets/Images/" . $record['name'] . " </td>";

echo "<td>" . "<input type=text name=topic value=" . $record['name'] . " </td>";

echo "<td>" . "<input type=text name=name value=" . $record['location'] . " </td>";

echo "<td>" . "<input type=text name=name value=" . $record['partners'] . " </td>";

echo "<td>" . "<input type=text name=description value=" . $record['description'] . " </td>";

echo "<td>" . "<input type=text name=description value=" . $record['date'] . " </td>";

echo "<td>" . "<input type=hidden name=hidden value=" . $record['location'] . " </td>";

echo "<td>" . "<input type=submit name=update value=update" . " </td>";
echo "<td>" . "<input type=submit name=delete value=delete" . " </td>";
echo "</tr>";
echo "</form>";
}
echo "<form action=mydata5.php method=post>";
echo "<tr>";

// echo "<td><input type=file name=uimage></td>";

?>

<td><input type="file" name="uimage" id="uimage"></td>

<?php
$file = $_FILES['uimage']['tmp_name'];
$image_name = mysql_real_escape_string($_FILES['uimage']['name']);
echo $_FILES['uimage']['error'];

echo "<td><input type=hidden name=uname></td>";
echo "<td><input type=text name=ulocation></td>";
echo "<td><input type=text name=upartners></td>";
echo "<td><input type=text name=udescription></td>";

echo "<td>" . "<input type=submit name=add value=add" . " </td>";
echo "</form>";
echo "</table>";
mysql_close($con);

?>

</body>
</html>

3 个答案:

答案 0 :(得分:2)

您需要在表单标记中添加enctype="multipart/form-data"

答案 1 :(得分:2)

对于文件类型字段,您需要在表单中添加enctype属性,以便可以使用$ _FILES

访问上传的文件

使用以下

更新表单的起始标记
<form action="mydata5.php"
method="post" enctype="multipart/form-data">

答案 2 :(得分:0)

检查您的插入查询。您使用 $ _ POST 作为图片名称。那是错的。