Reputation: 2278
I'm using a very simple php page to upload a file and display the image to same page; however, the image is not displaying. I checked whether the image was being uploaded and where, and it is being uploaded to the same directory as the php file.
<!doctype html>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>File Upload</h1>
<form method="post" action="upload.php" enctype="multipart/form-data">
Select File: <input type="file" name="filename" size="10" /><br/>
<input type="submit" value="upload" />
</form>
<?php
//checking if user uploaded image
if($_FILES) {
$name = $_FILES['filename']['name'];
move_uploaded_file($_FILES['filename']['tmp_name'], $name);
echo "Uploaded image $name <br/>";
echo "<img scr='$name' height='100px' width='100px'/>";
}
?>
</body>
</html>
Upvotes: 0
Views: 269
Reputation: 2147
Please check your upload.php
Write code as shown below.
echo "<img src='" . $name . "' />
";
when you write php variable in html ...you should concatenate that variable with .
Upvotes: 1
Reputation: 3986
echo "<img scr='$name' height='100px' width='100px'/>";
change to :
echo "<img src='{$name}' height='100px' width='100px'/>";
edit: Use curly brackets when including a variable in double quotes.
And please provide whole path of the image, like http://www.example.com/path/to/image/image.png
Upvotes: 1