Topic: download PHP looks in wrong place

My "localhost" is a Mac which keeps a user's web pages in ~/Sites. I tried the download button of JB 1.5 to download from my own site and got a file IMG_3130.jpg.html with a PHP error message:

Warning: readfile(/Library/WebServer/Documents/~axel/at/2016/01/images/IMG_3130.jpg): failed to open stream: No such file or directory in /Users/axel/Sites/at/2016/jbcore/juicebox.php on line 21

The script ought to have looked in /Users/axel/Sites/at/2016/01/images/IMG_3130.jpg, i.e., in the user's tree, not in the web server's tree.

Re: download PHP looks in wrong place

The 'juicebox.php' file builds the path to the image to be downloaded using $_SERVER['DOCUMENT_ROOT'] as the start of the path.
Normally, all files on a web server (such as a gallery and its images) will have just one shared root ($_SERVER['DOCUMENT_ROOT']).
The problem seems to be that you have two different file structures each with their own root.
I do not know what the imageURL (or linkURL) entries are in your gallery's XML file and where your gallery and images are located (whether they are downstream of /Library/ or /Users/) but if you want Juicebox to look for your images in a location other that your web server, then you might need to change your $_SERVER['DOCUMENT_ROOT'] value or edit the 'juicebox.php' file and hard-code the path you want to use instead of using $_SERVER['DOCUMENT_ROOT'].
If your gallery and images are effectively on different domains, then the Download Button will not work.
However, if your gallery uses a regular file structure (as created by JuiceboxBuilder-Pro) you are just using a local server for testing, then you should find that the Download Button functions correctly when the gallery has been uploaded to a regular web server (without any modifications required).

Re: download PHP looks in wrong place

The widely used Apache web server maps http://[host]/~[user]/[path] to a root in user's home directory, e.g., ~[user]/public_html/[path] (the Mac uses "Sites" rather than "public_html"). This is typical for a multiuser installation such as a university or a PC potentially shared by several users. It circumvents the problem that you can't give everybody access to the web server's own file structure and you don't want to explicitly upload using something like FTP.

Re: download PHP looks in wrong place

Essentially, the problem seems to be that $_SERVER['DOCUMENT_ROOT'] is pointing towards /Library/ rather than /Users/.
Is there any circumstance in your setup where you would want $_SERVER['DOCUMENT_ROOT'] to be pointing towards /Library/?
If not, and you always want $_SERVER['DOCUMENT_ROOT'] to be pointing towards /Users, then would changing DOCUMENT_ROOT in your server settings not be a possible solution?

As far as I am aware, it is not unusual to use $_SERVER['DOCUMENT_ROOT'] to fetch the document root directory.
I do not know of an alternative to $_SERVER['DOCUMENT_ROOT'] which would specifically support your setup (Apache server on Mac with two root directories) .
I think the best solution might be to ensure that $_SERVER['DOCUMENT_ROOT'] returns the path you want to use.

I've tried a web search for this problem and found the following forum threads which seems to be relevant.
https://forum.mamp.info/viewtopic.php?f=4&t=669
https://css-tricks.com/forums/topic/how … -x-simply/

If you are using MAMP, then the following suggestion (from the second link above) might help:
https://css-tricks.com/forums/topic/how … post-95005

Here are a few other links which relate to your setup (Apache server on Mac) and reference the document root. They may contain some information which will help.
http://superuser.com/questions/225346/h … -on-my-mac
https://coolestguidesontheplanet.com/in … n/#webroot
http://serverfault.com/questions/161529 … n-mac-os-x

Otherwise, a workaround would be to replace $_SERVER['DOCUMENT_ROOT'] in the 'juicebox.php' file with the path you want to use (or create a new PHP constant and use this instead of $_SERVER['DOCUMENT_ROOT'] in the 'juicebox.php' file).