hi i just started php, my code works on ie, bit when i open the webpage on firefox and chrome the image does not display?, can anyone help

$car = "C:\wamp\www\porche.jpg";
        
        
        $banner = "<img src=\"$car\" ";
        $banner .= "width=\"380\" height=\"110\" border=\"0\" >"; 
    
        
        echo($banner);

Dani AI

Generated

Short answer: the page is sending a Windows filesystem path to the browser instead of a URL-style path. As pointed out, browsers expect a web path (relative or root‑relative) and not a drive-letter/backslash filename. Older IE builds sometimes (mis)handled local paths on the same machine; modern Firefox and Chrome treat that as an invalid or blocked resource, so the image won’t load.

A practical approach:

  • Keep image files inside the web document tree and reference them with URL paths (forward slashes), either relative to the current script or root‑relative from the web root.
  • Use server-side checks when helpful: verify the file exists on disk with the document root, then output the corresponding URL path in the img tag.

Example of a simple server-side check and the correct URL output:

$fsPath = $_SERVER['DOCUMENT_ROOT'] . '/assets/img/car_photo.jpg';
if (is_file($fsPath)) {
    echo '<img src="/assets/img/car_photo.jpg" alt="photo">';
} else {
    echo '<!-- missing image: ' . htmlspecialchars($fsPath) . ' -->';
}

Troubleshooting checklist (fast): open page source and inspect the img src value; paste that src into the address bar to see if it 404s; watch the browser devtools network/console for blocked or 404 errors; confirm filename spelling and case (Windows is case‑insensitive, most Linux hosts are not); ensure file permissions allow webserver read access; use forward slashes in URLs.

For : if developing under WAMP, load pages via (not file:///…), and for deployment never leave Windows absolute paths in generated HTML. This keeps behavior consistent across browsers and when the site moves to a remote host.

Recommended Answers

All 3 Replies

If you change line 1 to:

$car = "porche.jpg";

it will work. You should never use an absolute path to a windows folder, because once you upload it to a webhost, it will no longer work.

thanks for that, it works but what if my image files are in another folder what do i do ?? dont i set a path ?

A relative path, from where your file is to your images, e.g. images/porsche.jpg

commented: great thanks +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.