JCChan
JCChan

Reputation: 465

Why my uploaded image didn't show on my php page?

Below is a main page for uploaded page:

<form id="form1" method="post" action="display.php" enctype="multipart/form-data" id="pro_image">
    <input type='file' onchange="readURL(this);" name="image" id="image"/>
    <br><img id="blah" src="profile pic.jpg" alt="your image" width="160px" height="120px"/><br/>
</form>

Incorporated with the image display page(display.php) script:

<?php
 $dir="upload/";
 $name=$_FILES['image']['name']; 
 $tmp=$_FILES['image']['tmp_name'];
 move_uploaded_file($tmp,$dir.$name);

 ?>

 <br /><img src="".$dir.$name."" width="100" height="100"/>

Anyone can help me to point out what the actual problem on display.php and correct my script?The image didn't show as desired on the page.

the output of display.php as show above: enter image description here

Upvotes: 2

Views: 599

Answers (3)

user2334807
user2334807

Reputation:

Your display.php file is a php file and you are try to show the variable data without echoing it in this file use it.

<img src="<?php echo $dir.$name; ?>" width="100" height="100"/>

EDITED:

move_uploaded_file($tmp,$dir.$name) or die("There is error in uploading");

Upvotes: 1

Ganesh Bora
Ganesh Bora

Reputation: 1153

  1. As first thing check that ur images uploaded properly on uploads/ folder. there is changes of permission issue to upload the images.

  2. then check manually accessing images by giving URL http://test.com/uploads/image1.jpg

  3. if all this debug with firebug what path is getting shown in

  4. if this path is wrong try to use absolute path rather than relative.

Upvotes: 0

Yogesh Suthar
Yogesh Suthar

Reputation: 30488

you forgot <?php ?> here

<img src="<?php echo $dir.$name; ?>" width="100" height="100"/>

Upvotes: 4

Related Questions