0

There is an image inside HTML page. I use Jquery for 360 grad rotation. My Jquery plugin gets the list of all images via AJAX request. But the problem is, that I don't know where the user will locate scripts ang images.

For example images will be located at home/mypage/public_html/gallery/pictures/ and scripts at home/mypage/public_html/scripts/rotate/. I have an option for user to show the path to scripts and want the script to get images path automatic, based on first image path.

For example I have some image with relative path:

<img src='pictures/001.jpg'>

url is: mypage.com/gallery/pictures/001.jpg

How can I get a path to containing folder in form:

home/mypage/public_html/gallery/pictures/

It's no matter to do it with Jquery or PHP

a PHP script then loads all images from home/mypage/public_html/gallery/pictures/

Thx!

4 Answers 4

1
<img src='<?php echo $_SERVER['DOCUMENT_ROOT'] ?>/gallery/pictures/001.jpg'>

try this

Sign up to request clarification or add additional context in comments.

Comments

0

In the end it depends on whether you process your data on the server side (PHP) or on the client side (JavaScript), but you need to use the getcwd() PHP function:

http://il.php.net/manual/en/function.getcwd.php

So you can pass the relative image path to PHP through jQuery, and then append the current working directory (getcwd) to the beginning.

2 Comments

There is an image inside HTML page. I use Jquery for 360 grad rotation. My Jquery plugin gets the list of all images via AJAX request. But the problem is, that I don't know where the user will locate scripts ang images. For example images will be located at home/mypage/public_html/gallery/pictures/ and scripts at home/mypage/public_html/scripts. I have an option for user to show the scripts path and want the script to get images path automatic, based on first image path.
but how can i get the relative path (not from src attribute, but from page root) with jquery?
0

How about this:

$_SERVER['DOCUMENT_ROOT'];

1 Comment

yes, i've tryed it $dir = $_SERVER['DOCUMENT_ROOT'].'/showroom/example/'.$imagedir; but how can i get the '/showroom/example/' part with a script?
0

Path of mypage.com\ plus gallery\pictures plus Image name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.