使用PHP无法使用img src检索图像

I'm working in local using WAMP, the structure of my website root folder is this:

MySite

  • Images
    • image1.png
    • image2.jpeg
    • ...
  • Directory1
    • file1.php
    • file2.php
  • Directory2
    • file3.php
    • file4.php

Well, I'm into file2.php and I would retrieve some of the images inside the directory 'Images'. I tried in several ways but I failed everytime.

The relative file path in your case should include a link to one level above your current page. To access the images in the structure you posted, use:

<img src="../images/myimage.jpg" />

Note the .., which tell the web server to seek the image one level above, and then go into the image dir.

have you tried ../images/[name of image]?

Try with a relative path like:

../images/<image filename>

Or with an absolute path to wherever the images directory belongs. E.g.:

C:\wamp\www\<...>\images\<image filename>

I recomend the first way because if you happen to move the website directory to somewhere else it would still work.

In your file2.php

//Read the file in binary
$imagen = file_get_contents('image1.png');

//Convert the binary to Base64 (string of numbers a chars)
$imageData = base64_encode($imagen);

//retrive the string
echo $imageData

And to call the image

<img src='data:image/png;base64, <?PHP include 'file2.php' ?>'/>;