任何人都可以告诉我这段代码有什么问题,我收到以下错误
Notice: Undefined index: media_type in C:\wamp\www\VirtualLibrary\upload_file.php on line 10
Notice: Undefined index: file in C:\wamp\www\VirtualLibrary\upload_file.php on line 14
Notice: Undefined index: file in C:\wamp\www\VirtualLibrary\upload_file.php on line 20
Notice: Undefined index: file in C:\wamp\www\VirtualLibrary\upload_file.php on line 22
这是我的代码
<html>
<head>
<title>Virtual Library</title>
<link href="css/login.css" rel="stylesheet"/>
<link href="css/style.css" rel="stylesheet"/>
<script type="text/javascript" src="scripts/ajax_search.js"></script>
</head>
<body>
<div id="wrapper">
<div id="header" align="center">
<ul align="center">
<li><a href="index.php"><span>Home</span></a></li>
<li><a href="news.html"><span>Top 100 Downloads</span></a></li>
<?php if(isset($_SESSION['login_user']))
{
$uname = $_SESSION['login_user'];
echo "<li><a href='upload.php'><span>Upload</span></a></li>";
}?>
<?php if(isset($_SESSION['login_user']))
{
$uname = $_SESSION['login_user'];
echo "<li><a href='profile.php'><span>$uname</span></a></li>";
echo "<li><a href='logout.php'><span>LogOut</span></a></li>";
}
else{
echo "<li><a href='login.php'><span>Member Login</span></a></li>";
echo "<li><a href='register.php'><span>Register</span></a></li>";
}
?>
<li><a href="downloads.html"><span>RSS <img src="images/rss.gif" id="rss"></span></a></li>
</ul>
</div>
<div class='frmdiv'>
<form action='upload_file.php' method='post' enctype='multipart/form-data'>
<table width='38%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td colspan='2'><div align='center'><font size='2' face='verdana'>Upload File</font></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan='2'><hr></td>
</tr>
<tr>
<td height='26'><font size='2' face='verdana'>FileName </font></td>
<td><font size='2' face='verdana'>
<input type='file' name='file' ></font>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td></td>
<td><select name='media_type' >
<option value='' selected>Select a media type...</option>
<option value='pdf'>PDF</option>
<option value='chm'>CHM</option>
<option value='epub'>EPUB</option>
<option value='html'>HTML</option>
<option value='djvu'>DJVU</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><font size='2' face='verdana'>
<input type='submit' name='Submit' value='Upload'></font>
</td>
</tr>
<tr>
<td colspan='2'><hr></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
<div align='center'>
}
</div>
</body>
</html>
这是upload_file.php
<?php
require('include/connection.php');
session_start();
?>
<?php
foreach ($_POST as $var => $value) {
echo "$var = $value<br>n";
}
$meditype = $_POST['media_type'];
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
if (file_exists($meditype . "/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"], $meditype . "/" . $_FILES["file"]["name"]);
}
}
?>
答案 0 :(得分:2)
您没有检查帖子数据是否存在。使用isset来执行此操作。实施例
if (isset($_POST['media_type'])) {
// Media type field was posted
}
答案 1 :(得分:0)
请不要针对相同的基本问题创建单独的问题:Getting the value of a combo-box using post method