I got a little problem. I am working on a project and I got my root, then I got 2 folders: website1
and website2
.
website1
is the staff panel, where the upload script is on (where this problem is on). website2
is the website the 'customer' will see. Here all the uploaded images, PDFs etc. are uploaded to.
So, I have a few notes before I start:
- I cannot use PHP in my Javascript. The Javascript is in .js files and not in my .php file.
- I cannot do this at my AJAX request as something client-side has to be done correctly to see the image.
So basically, I am in website1
and when I upload a file (with DropzoneJS (http://www.dropzonejs.com/)) it does a AJAX request. Here it has to upload a file to a directory in website2
. In website1
I have to see that image after uploading it in a IMG tag.
So in PHP I got this:
$uploadPath = filter_input(INPUT_POST, 'uploadPath');
$uploadPath = dirname(getenv('DOCUMENT_ROOT')) . '/' . $uploadPath;
This works and the file gets uploaded to that directory. $uploadPath
is this (in Javascript, sent as POST parameter in AJAX request):
/SITE2/assets/uploads/
Now I need to translate the dirname
and getenv('DOCUMENT_ROOT')
into Javascript. I tried document.location.hostname
but this does return a different value than getenv('DOCUMENT_ROOT')
.
document.location.hostname
: 127.0.0.1
getenv('DOCUMENT_ROOT')
: D:/xampp/htdocs
How can I get the same value as getenv('DOCUMENT_ROOT')
in Javascript?