Bruce
Bruce

Reputation: 567

Can't display image with PHP script

I am a newbie in PHP script, I try to display image which is uploaded from my android phone. With my script, I upload success image to server, but I can't display image to webpage

I up PHP script here and my image (uploaded_image.jpg) in same folder:

folder

This is PHP code:

<?php
$base=$_REQUEST['image'];
 $binary=base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
$file = fopen('uploaded_image.jpg', 'wb');
fwrite($file, $binary);
fclose($file);


$path = "publib_html/"; 
$tmp_name = $_FILES['file']['tmp_name'];
$name = $_FILES['file']['name'];
$type = $_FILES['file']['type']; 
$size = $_FILES['file']['size']; 

move_uploaded_file($tmp_name,$path.$name);

?>

It just upload and don't show my image. This is a thing which displayed here:

image

I was try to add this code echo '<img src="'. $path. '/'. $file. '" alt="'. $file. $

But nothing happen. How can I display image which in same folder with PHP script?

Upvotes: 2

Views: 2787

Answers (1)

Shomz
Shomz

Reputation: 37701

$path refers to a path in the file system, while for the image, you need a URL path, so this part:

echo '<img src="'. $path. '/'. $file. '" ...

will fail (even when you fix "publib_html"), instead, you can simply do:

echo '<img src="uploaded_image.jpg" ...

Upvotes: 1

Related Questions