0

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>
miatech
  • 2,150
  • 8
  • 41
  • 78

2 Answers2

1
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

Brett Santore
  • 799
  • 6
  • 14
prava
  • 3,916
  • 2
  • 24
  • 35
1
  1. Please check your upload.php

  2. Write code as shown below.

echo "<img src='" . $name . "' />";

when you write php variable in html ...you should concatenate that variable with .

prava
  • 3,916
  • 2
  • 24
  • 35
Prashant Tapase
  • 2,132
  • 2
  • 25
  • 34
  • You need to change to : `echo "";`, just need to add single quotes for `src attribute`, otherwise everything is fine (y) :) – prava Jul 21 '14 at 10:36