HTML文件:
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
PHP文件(upload.php):
<?php
$uploaddir = 'new/';
$uploadfile = $uploaddir .
basename($_FILES['userfile']['name']);
echo "<p>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded. $uploadfile \n";
} else {
echo "Upload failed";
}
echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
我正在使用这个PHP代码。但上传后显示它失败了。为什么会失败。这是一个演示测试,http://labrat.herobo.com/g.html
答案 0 :(得分:2)
没有输入标记与userfile
。
请更改
$_FILES['userfile'] to $_FILES['fileToUpload']
OR
<input type="file" name="fileToUpload" id="fileToUpload"> to <input type="file" name="userfile" id="fileToUpload">