0
我想要建立一個文件上傳的網站! 這裏是我的代碼: 的index.php:試圖上傳一個文件
<?php include('/inc/header.php'); ?>
<?php
if($_SESSION['username'] != null)
{
echo "
<form class=\"form-horizontal\" method=\"post\" action=\"inc/sumbitfinish.php\" enctype=\"multipart/form-data\">
<!-- Text input-->
<div class=\"form-group\">
<label class=\"col-md-4 control-label\" for=\"Your Name\">Name</label>
<div class=\"col-md-4\">
<input id=\"Your Name\" name=\"namew\" type=\"text\" placeholder=\"placeholder\" class=\"form-control input-md\" required=\"\">
</div>
</div>
<!-- Text input-->
<div class=\"form-group\">
<label class=\"col-md-4 control-label\" for=\"Home Work Code\">Home Work Code</label>
<div class=\"col-md-4\">
<input id=\"Home Work Code\" name=\"code\" type=\"text\" placeholder=\"placeholder\" class=\"form-control input-md\">
</div>
</div>
<!-- Textarea -->
<div class=\"form-group\">
<label class=\"col-md-4 control-label\" for=\"textarea\">Additional Imformation </label>
<div class=\"col-md-4\">
<textarea class=\"form-control\" id=\"textarea\" name=\"add\">default text</textarea>
</div>
</div>
<!-- File Button -->
<div class=\"form-group\">
<label class=\"col-md-4 control-label\" for=\"filebutton\">File Button</label>
<div class=\"col-md-4\">
<input id=\"ufile\" name=\"ufile\" class=\"input-file\" type=\"file\">
</div>
</div>
<!-- Button -->
<div class=\"form-group\">
<label class=\"col-md-4 control-label\" for=\"\"></label>
<div class=\"col-md-4\">
<button id=\"Submit\" name=\"sumbit\" value=\"Sumbit\" class=\"btn btn-primary\">Hand In</button>
</div>
</div>
</fieldset>
</form>
";
}
else
{
echo "<script language=\"javascript\">";
echo "alert(\"You don\'t have permission to access this page\")";
echo "</script>";
echo "<meta http-equiv=REFRESH CONTENT=0;url=/index.php>";
};
?>
sumbitfinish.php
<?php session_start(); ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
include('mysql.php');
echo $_FILES["file"]["name"];
?>
我已經簡化了上傳代碼, 但它仍然顯示錯誤按摩
Undefined index: file in C:\xampp\htdocs\system\inc\sumbitfinish.php on line 6
問題是什麼? 我還需要同時向MySQL發送數據, 這是功能不能同時工作的那個?
哦!多麼粗心的錯誤! –