Reputation: 845
I have a PHP script (index.php) that includes an index.html file in a sub-directory (site1.com). This index.html file displays images that are located in the same directory (site1.com).
Right now, the index.php file includes the index.html file. The html from index.html is shown, but the images are not. The index.html file is looking in the ROOT directory for the images to display. This is the problem. I'd like to somehow include all contents (??) of the site1.com directory, not just the single 'index.html' file.
I've tried changing the working directory, but have had no success. Maybe I'm just not using it correctly...
For reasons that I'd rather not go into explaining, I do not want to edit any configuration settings in PHP or Apache. I also would not like to modify the code of index.html. Basically put, I need to find a solution that can be 100% implemented in PHP. The url needs to appear as though the user is still in the root directory (mysite.com) when, in reality, the content from the sub-directory (site1.com) is being shown. This is sort of like a transparent proxy, in a way.
[FILE] index.php
[DIR] site1.com
[FILE] index.html
[FILE] img1.png
[FILE] img2.png
[DIR] site2.com
[FILE] index.html
[FILE] img1.png
[FILE] img2.png
I have done plenty of searching, but have not found a working solution.
Upvotes: 1
Views: 215
Reputation: 360802
When you include()/require() a file, it's as if the contents of that file were literally cut/pasted into the script doing the including. If index.html uses images in the site1.com directory, you'll have to refer to those image using paths based on the location of index.php.
The remote user can NOT tell that you've included a file from a subdirectory on your site - they'll just see some html coming back from your server, so if your index.html has something like
<img src="img1.png" />
in it, but that html is being displayed from the index.php script, then the browser is going to be looking for
http://example.com/img1.png
not
http://example.com/site1.com/img1.png
It's up to YOU to output proper paths.
Upvotes: 1