dmubu
dmubu

Reputation: 1143

Images Not Loading in XAMPP

I am writing a program that dynamically generates dice and loads the corresponding image. Everything works, except the images never load using localhost. Something must be wrong with my path. Whether I use the relative or absolute path, no image loads.

The absolute path is: C:\xampp\htdocs\php6-mysql\3\die1.png

Alas, I created a most basic HTML page, and the image still doesn't load. Any ideas? Is this a problem with XAMPP?

<!DOCTYPE html>
<html>
<head>
    <title>Here are your dice!</title>
</head>
    <body>
        <img src="die1.png">
    </body>
</html>

Upvotes: 1

Views: 17989

Answers (5)

na8ur
na8ur

Reputation: 1

what worked for me is reading the file and directly adding it to the src as base64_encoded. In PHP

$data  = file_get_contents($path.$filename);
$out[] = '<img src="data:image/png;base64,'.base64_encode($data).'" width="100" height="100" alt="" />';
 

Upvotes: 0

user19730218
user19730218

Reputation: 1

like you opened the php file after replacing your file with dashboard from "localhost/dashboard" do the same like: before your file address was: "file:///F:/download/xamp/htdocs/icons8-pavlova-100.png" after: "http://localhost/icons8-pavlova-100.png" this way it will show.

Upvotes: 0

ceotimgorman
ceotimgorman

Reputation: 1

You can use an image from online sources. For instance, you can have your pictures in dropbox and retrieve them from there. Here is the code:

<a href="#"><img src="URL" alt=""></a>

That should help you to play around with images as you look for a better solution.

Upvotes: 0

Jesse
Jesse

Reputation: 67

You have to set read/write permissions for each image. I believe you can do the whole folder but if that doesnt work do each image individually. right click(two finger mac) => get info => read and write for all of them. reload and presto, you got images through xampp.enter image description here

Upvotes: 2

Mark
Mark

Reputation: 8441

You should place your image inside htdocs. It is the root of your page. or this /php6-mysql/3/die1.png to your html <img src tag.

Upvotes: 0

Related Questions