为什么下面这段php代码上传文件总是失败???
代码是:
<html>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="file.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
</html>
//file.php
<?php
$uploaddir = './var/';
echo $uploaddir ;
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo $uploadfile;
echo '<br>Come in <br>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
echo 'Here is some more debugging info:';
print_r($_FILES);
}
?>
参考答案:我试了下,你的代码没问题,是不是你的VAR文件夹是只读或者不是777啊