在PHP中显示图像时出错

I'm trying to understand how the file systems work in PHP. I created a small example to display an image from a folder but instead of printing the image I think I'm printing the contents.

<?php
  $image = "/path/to/image.jpg";
  $myfile = fopen($image, "r") or die("Unable to open file!");

  $logo = fread($myfile,filesize($image));
  echo"<img src=\"$logo\" width=\"100\" height=\"100\"\/>"; 
?>

Did I happen to write a command wrong or miss something I needed to do?

Your data is not a path,but the file's content, and it is OK, but you must use data URI syntax:

$logo = "data:image/jpg;base64,".base64_encode($logo);
echo"<img src=\"$logo\" width=\"100\" height=\"100\"\/>"; 

See similar thread here: Unable to display image from MySQL table

The img src attribute takes a filename and does it's own process to read the image and actually display it. If you open an image file with a text editor you'll get interesting gibberish. What you tried to do in the above code is put that gibberish in the src. You can see that if you do View Source in your browser.

If you want to show an image you don't actually need php, this would simply be <img src="/path/to/image.jpg"> providing the path is inside your webroot.

You need to provide the image url as the src and NOT it's content, like this :

$log = "http://ideone.com/gfx2/img/spoj.png";

echo "<img src='$log' width='100' height='100'/>"; 

DEMO

Let's say the image is on the same directory as the html page, then you can simply use:

$log = "spoj.png";
echo "<img src='$log' width='100' height='100'/>"; 

Let's imagine the image is inside a directory named images on the same directory as the html page, then you can use:

$log = "images/spoj.png";
echo "<img src='$log' width='100' height='100'/>";