我已经编写了上传文件到服务器的代码,如下所示。如何使用smarty将文件上传到服务器?
Home.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>
upload_file.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);
}
但我得到 '未定义指数:文件' 的错误。请帮我摆脱那里。
你什么时候得到'未定义的索引:文件'错误? –
在你的'upload_file.php'中首先执行'var_dump($ _ FILES);'并检查它是否看起来像你期望的那样。 –
@Martinperry:当执行到达该行'if(($ _FILES [“file”] [“size”]> 0))''。我去那儿。 – soundy