我已经编写了将文件上传到服务器的代码,如下所示。
主页.tpl
<form enctype="multipart/form-data" method="post" action="upload_file.php" >
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
上传文件.php
if(($_FILES["file"]["size"] > 0))
{
$fileName = $_FILES["file"]["name"];//the files name takes from the HTML form
$fileTmpLoc = $_FILES["file"]["tmp_name"];//file in the PHP tmp folder
$fileType = $_FILES["file"]["type"];//the type of file
$fileSize = $_FILES["file"]["size"];//file size in bytes
$fileErrorMsg = $_FILES["file"]["error"];//0 for false and 1 for true
$target_path = "uploads/" . basename( $_FILES["file"]["name"]);
$moveResult = move_uploaded_file($fileTmpLoc, $target_path);
}
但是我收到“未定义的索引:文件”错误。请帮我摆脱那里。