Displaying an image in another Drive

<img src="/oldImage.jpg" style="width:100px;height:100px">

I have the code above at localhost/imgTest.php.

if I open the php file with the url at http://localhost/imgTest.php in my computer,
the image “oldImage.jpg” is well displayed.

I have another image named "newImage.jpg in another drive (G:) of the same computer.
The new path of the image is (G:)/load/newImage.jpg.

The path of the php file is (F:)/xampp20210115/htdocs/imgTest.php

Can I make it well display the new image “newImage.jpg”.

The code below is one of my trials.

<img src="/oldImage.png" style="width:100px;height:100px">
<img src="G://load/newImage.png" style="width:100px;height:100px">

The oldImage.jpg is well displayed while the newImage.jpg is not displayed with the code above.
Although the newImage.jpg is not well displayed with the code above, it shows, I hope, what I want.

You need to understand the difference between virtual paths (such as /oldImage.png, which is in the virtual root but almost certainly not in the actual root directory of your server) and physical paths (such as the one with the drive code before it). URLs (which are virtual paths) generally don’t have drive codes in them.

You could configure the web server to have a virtual folder pointing to that physical folder on your G drive, and then just use that folder name when you want to access that drive - exactly how you do that will depend on what server you are running on.

I believe you could also load the contents of the file and then output the appropriate headers followed by that content, and display the image that way. I’ve seen code on here to do that, but quite some time ago.

They say on the internet that I can make a virtualhost by editing httpd-vhosts.conf.

Can I use two hosts including a virtual host at a same time in my XAMPP?

Do you want to display something from your desktop drive on the internet? Remember, if they can hack your server because you don’t know how to harden the server, you may be giving them an open door to your desktop computer as well.

Do you really want to do that?

No, I don’t want that my desktop drive is hacked.

I have two questions like the following.

(1) Do you mean XAMPP is not proper for displaying something from my desktop drive on the internet due to security issue?

(2) Should I study more about security enough to displaying my php files on the internet through XAMPP?

You should be aware of the security implications of opening up your server to the internet, yes.

Thank to you, I now know that my question is related to virtual host or virtual folder.
I think I need some study about virtual host in xampp windows 10 by googling.
As the virtual host matter belongs to The forum of Server config, my next question will be on the Server config.

I cannot find an authoritative source, but XAMPP is a development stack and is not intended for use as a live server.


I have a php file at F:/xampp210707_2/test.php
And I have an image at G:/load/img1.png.
Since the drive (F:) which has php files is different from the drive (G:) which has img1.png,
I added the following at (F:) xampp210707_2/apache/conf/extra/httpd-vhost.conf

Alias /load "G:/load"
<Directory "G:/load">
Require all granted

The file “tes.php” has the code below.

echo '<img src="load/img1.png">';

With the code above “img1.png” is well displayed although the image “load/img1.png” is not drive (F:) but (G::).
So far so good.
but as I add the code below in the file “test.php”,

if ( file_exists('load/img1.png') ) {

echo 'Yes, there is the image "load/img1.png"';

} else {

echo 'No, there is no such an image file "load/img1.png"';


The result of the code above is "No, there is no such an image file “load/img1.png”, although there is tthe image “load/img1.png” at (G:)/

As I put the image at F:/xampp210707_2/htdocs/load/img1.png, the result of the code above says "Yes, there is the image “load/img1.png”.

I think that the code " file_exist" does NOT recognize Alias /load “G:/load” but recognize only htdocs/load.
Can I make it recognize the image file in G:/load with your help?

“/load” and “load/” are not the same thing. One is relative to the root, one is relative to the page being executed.

That being said…why not just copy it into the web path? Images are small in size…

Do you mean "G:/load/img1.png which size is 5.25KB and “F:/xampp210707_2/htdocs/load/img1.png” which size is 0 byte?

Apache doesn’t understand Windows drive letters. You would be better off putting the image in the web server’s file system.

1 Like

I have merged this with your previous post on the subject. As mentioned before, please do not start duplicate posts on the same subject.

1 Like

The easiest way is to define where the images can be found using some configuration. There are multiple ways to do this, but the easiest would be to define a constant.

define('IMAGE_FOLDER', 'G:/load');

if (file_exists(IMAGE_FOLDER . '/img1.png')) {
    echo 'Yes, there is the image "load/img1.png"';
} else {
    echo 'No, there is no such an image file "load/img1.png"';

So now every time you reference an image just use that constant IMAGE_FOLDER. If it ever moves you only need to change the value there and you’re done.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.