在用户点击上传后的程序中,为什么图片不显示在页面上?
即使在我点击上传后,它仍然说"不工作lol"。不知道我哪里出错了。
upload.php的:
<html><head><title>PHP Form Upload</title></head><body>
<form method='post' action='upload.php' enctype='multipart'/form-data'>
Select File: <input type='file' name='filename' size'500' />
<input type='submit' value='Upload' />
</form>
<?php
if($_FILES)
{
$name = $_FILES['filename']['name'];
move_uploaded_file($_FILES['filename']['tmp_name'], $name);
echo "Uploaded image '$name'<br /><img src='$name' />";
}
else echo "not working lol";
?>
</body></html>
答案 0 :(得分:2)
让你的HTML正确。
+ enctype='multipart'/form-data'
- enctype='multipart/form-data'
如果你没有像这样回复html,那么这将更容易被发现。
<html>
<head>
<title>PHP Form Upload</title>
</head>
<body>
<form method='post' action='upload.php' enctype='multipart/form-data'>
Select File: <input type='file' name='filename' size'500' />
<input type='submit' value='Upload' />
</form>
<?php
if ($_FILES):
$name = $_FILES['filename']['name'];
move_uploaded_file($_FILES['filename']['tmp_name'], $name);
?>
Uploaded image <?= $name;?><br /><img src="<?= $name;?>"/>
<?php else: ?>
not working lol
<?php endif;?>
</body>
</html>