Jump to content

IMG SRC wrong path from XAMPP localhost


grissom

Recommended Posts

Hi all

 

I am running XAMPP on my laptop and working with files not in the localhost directory.  For functions like fopen, there is no problem, I specify a path starting from the localhost directory to wherever I want to work and that's fine.

 

For some reason though, it is NOT working with IMG SRC.  I get my PHP to generate the following line of code :

 

<IMG SRC = "http://localhost/../../../wherever/android.jpg">

 

(which in this case points to C:\wherever\android.jpg)

 

However the browser misses the middle bit of the URL out and interprets it just as localhost/wherever/android.jpg - which clearly doesn't exist !

 

Likewise, if I try typing the address straight into the address bar, the '../../../' bit of it immediately vanishes.

 

I've tried formatting the URL in a variety of ways, none of them seem to work, where am I going wrong ?  Many thanks !

 

Link to comment
https://forums.phpfreaks.com/topic/235346-img-src-wrong-path-from-xampp-localhost/
Share on other sites

fopen() and other php functions use a path relative to the filesystem root. HTML tags use a path relative to the web document root. It isn't likely that there are sufficient permissions for the image to be grabbed from a directory above the web root. For that reason, you should organize the directory structure as it would be on a live production server.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.