我有这个HTML代码,用于将文件发布到我的上传脚本:
<!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>
<title>CONTISEC PORTAL - NEW USER</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="buttcss/gstyle_buttons.css" type="text/css" media="screen">
<link rel="stylesheet" type="text/css" href="usercon.css" />
</head>
<body>
<div id="page-wrap">
<p>CREATE NEW CLIENT USER ACCOUNT BY ENTERTING CLIENT REFERENCE NUMBER (supplied by Pershing) AND DESIRED USERNAME.</p>
<div id="contact-area">
<form method="post" action="fileproc.php">
<enctype="multipart/form-data">
<label for="client_ref">BROWSE:</label>
<input type="file" name="file" id="file" />
<label for="client_ref">SELECT FILE:</label>
<select name="file">
<option value="assets" >ASSETS (DAILY)</option>
<option value="stock_names" >STOCK_NAMES (DAILY)</option>
<option value="client_names" >CLIENT_NAMES</option>
</select>
<div class="buttons">
<button class="action redbtn" type="submit"><span class="label">SUBMIT</span></button>
</form>
<div style="clear: both;"></div>
</div>
</div>
</body>
</html>
这是我的上传脚本(来自w3学校):
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>
但是,当页面加载时,它会显示“未定义的索引”错误。 有人知道为什么会这样吗?
答案 0 :(得分:1)
将以下内容添加到表单打开标记中。它是上传文件所必需的
enctype="multipart/form-data"
答案 1 :(得分:0)
Sam您对文件选择字段和选择字段具有相同的名称,这必须导致问题。
<input type="file" name="file" id="file" />
<select name="file">