In my program after the user clicks upload, why doesn't the image appear on the page?
Even after I click upload it still says "not working lol". Not sure where I've gone wrong.
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>
Get your html right.
+ enctype='multipart'/form-data'
- enctype='multipart/form-data'
This would be easier to spot if you did not echo html, like this.
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.