php文件上传的问题
我用php写了一个简单的文件上传的页面,显示上传成功了,但
(1)、对应目录下却没有上传的文件【tmp目录下没有文件,也没有生成upload目录和文件】。
(2)、move_uploaded_file的参数顺序,代码中上一行的为错误的,下一行正确,与教材上的相反。
求大神解惑。
upload.html
<form action = "upload_file.php" method = "post" enctype = "multipart/form-data">
<label for = "file">Filename</label>
<input type = "file" name = "file" id = "file"/>
<br>
<input type = "submit" name = "submit" value = "上传"/>
</form>
<?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"]."<br>";
if(file_exists("upload/".$_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"]." already exists.";
}
else
{
//move_uploaded_file($_FILES["file"]["tmp_name"], "upload/".$_FILES["file"]["name"]);// 报错
move_uploaded_file("upload/".$_FILES["file"]["name"],$_FILES["file"]["tmp_name"]);
echo "<br><br><br> Storeed in: "."upload/".$_FILES["file"]["name"];
}
}
?>