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.
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.
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 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
</Directory>
The file “tes.php” has the code below.
<?php
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?
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.