How to pass one local URL to functions in another local URL

Problems with the Windows version of XAMPP, questions, comments, and anything related.

How to pass one local URL to functions in another local URL

Postby TomXampp » 13. September 2015 15:33

I'm calling content from one locally hosted site for use on another locally hosted site. (This is for the purposes of reproducing a cookieless URL from which I'll serve static content.)

I'm using the current version of XAMPP (5.6.12) with PHP version 5.6.12 and Apache 2.4.16 (Win32) on Windows 8.1.

The two sites (both found off of the \xampp\htdocs directory) are MAIN and STATIC, and are configured appropriately in the httpd-vhosts.conf file as well in the Windows hosts file. So, they each work, and each can retrieve content from the other (with the important exception explained below).

In STATIC there is a subdirectory named IMAGES containing MY.JPG; its local URL is therefore STATIC/IMAGES/MY.JPG when XAMPP is running, and it does display.

Within the files of my MAIN local domain, I can reference content on the STATIC local domain by prefixing the domain name with two forward-slashes, e.g., //STATIC/IMAGES/MY.JPG. And in fact, this code in my STATIC domain's INDEX.PHP will in fact retrieve and display the JPG:

Code: Select all
<img style="display: inline;" src="//STATIC/IMAGES/MY.JPG" />

No problem there. But when I pass that path to getimagesize() or other PHP operators, like this:

Code: Select all
$resource = "//STATIC/IMAGES/MY.JPG";
$getimagesize = getimagesize($resource);

...I get a message like this:

Warning: getimagesize(//tmb-static/images/my.jpg): failed to open stream: Permission denied in C:\xampp\htdocs\MAIN\INDEX.PHP on line 11

After reading about similar problems encountered by others, I checked to ensure that correct permissions are set for the folder I'm trying to open. To determine who the current user is when I execute this code locally, I ran:

Code: Select all
$current_user = get_current_user();
print_r("current_user = " . $current_user . "\n");

...and it showed that the current user is SYSTEM.

I then did what has been suggested elsewhere, which is to give complete read, write, and all other accesses to SYSTEM for the STATIC folder and its subfolders, by following the appropriate steps for sharing folders and setting permission. I did this not only for SYSTEM but also for Everyone, just in case.

Sadly, getimagesize() and similar operators throw the same "failed to open stream: Permission denied" message when I then ran the code, even though the image itself can be retrieved and displayed using simple HTML:

Code: Select all
// This works and displays the retrieved image:
echo '<img style="display: inline;" src="//STATIC/IMAGES/MY.JPG" />';

// This immediately fails with message: "failed to open stream: Permission denied..."
$getimagesize = getimagesize('//STATIC/IMAGES/MY.JPG');

Provided that I've given full control to the STATIC folder and subfolders, as well as to the parent HTDOCS folder as well, what could be the cause and solution to this vexing problem?

UPDATE: By prefixing the STATIC URL with http:, like this:

Code: Select all

...the error changes to

failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

But is this a red herring? Or is this just another layer of the problem, with the prefixing of HTTP: being the first step?
Posts: 26
Joined: 12. March 2015 03:58
Operating System: Windows 8.1

Re: How to pass one local URL to functions in another local

Postby Alex R4 » 14. September 2015 08:47

$resource = "//STATIC/IMAGES/MY.JPG";
$getimagesize = getimagesize($resource);

This is the wrong approach. When in app=SYSTEM the base path is htdocs/SYSTEM. To get the path to your STATIC you may use $resource = "../STATIC/images/my.jpg"
The permission of the STATIC folder must be set read so getimagesize() can go through.

http://STATIC/IMAGES/MY.JPG ==> This is completely wrong.

System routines in php require either an absolute path ( or a relative path based on the location of the first php being activated. In your case: htdocs/SYSTEM

Also, from a design point of view your approach SYSTEM accessing STATIC will get you in trouble some time in the future. What you are doing is welding application SYSTEM and STATIC together for good.
Modern design is trying to get away from this. It's called "Separation of Concern".
Alex R4
Posts: 31
Joined: 08. April 2014 11:24
Location: Adelaide/Australia
Operating System: Windows 7

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 84 guests