2

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?

5
  • I assume this is a typo in your question "publib_html/". What happens if you add /uploaded_image.jpg to the end of whatever URL is shown in your linked image? Commented May 14, 2016 at 4:28
  • No thing happen, it still display index of / upload_image.php and uploaded_image.jpg Commented May 14, 2016 at 4:43
  • That's hard to believe. Please confirm "publib_html/" is a typo. Commented May 14, 2016 at 4:48
  • what is $path and $file? Commented May 14, 2016 at 5:06
  • Dear BillK, " Please confirm "publib_html/" is a typo". I still don't understand what your mean, sorry i just study c, c++ and i have just move to php recently to design web, i don't know so much. Dear hjpotter92 $path is a link to image $path = "publib_html/"; and $file is my image, i think so Commented May 14, 2016 at 5:21

1 Answer 1

1

$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" ...
Sign up to request clarification or add additional context in comments.

3 Comments

I was try your code, but it still no change, it seem to be not run upload_image.php script, i feel like that. Do you know another web to upload image like that, i write app upload image to server and maybe i think i need a available server first to test whether my image was uploaded yet
I don't understand all of that. You need to provide more info. It could be that your image is getting uploaded someplace else because of the typo in your path, try searching your system for another file with that name. To test my answer, you can create a new php file with only echo '<img src="uploaded_image.jpg">'; inside, and you'll see it will show the image as long as they are in the same directory.
Yes, it's run. i create a new php with just your 1 line code and rename is "index.php". It's run and show image, now i think what should i do next, thank you so much for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.