473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Newbie -- pass document.location to php

I am sure this must be common but I can't seem to find how to do it.

I have a file structure as follows:
php
- getimages.php
gallery
- index.html
- image1.jpg
- image2.jpg
- image3.jpg

inside of index.html I have
<a href="http://bytes.com/submit/304/ ../php/getimages.php">View images</a>

what I want to do is in getimages.php be able to set the directory to ./gallery

Naturally I can hard code this but I would like to have a generic solution just in case I move my php folder, or have a more complex directory structure.

I thought i could solve this in two ways
1) send document.location from index.html, something like this:
<a href="./php/getimages.php?document.location" ....
(notice I have index.html, not a php file and I can't change this)
2) in getimages.php somehow determine where the request is coming from, maybe use REQUEST_URI

But I am sure there must be a more elegant approach.
Aug 26 '09 #1
4 3794
dlite922
1,584 Expert 1GB
I still don't see your reasoning for why you wouldn't just redirect to that folder, but use php header("Location: gallery/").

Am I understanding you wrong?



Dan
Aug 27 '09 #2
Sorry I am not sure I understand what you are asking ( or perhaps how header works) but my issue is that I also want to call the same file getimages.php and it needs to load the files from the location of the calling index.html.

So if index.html is in ../gallery/ then run get images from ../gallery. If index.html is in ../gallery2/ then it should get the images from gallery 2 etc.

So my side structure is more complex than this, and looks more like:
php
- getimages.php
2002
- 01gallery
- index.html
- image1.jpg
- image2.jpg
- 01gallery
- index.html
- image1.jpg
- image2.jpg
- 02gallery
- index.html
- image1.jpg
- image2.jpg
- 04gallery
- index.html
- image1.jpg
- image2.jpg
etc (for 2003, 2004, ...)

Does that make sense?

I did write this bit of code to get it to work but it seems a bit of an overkill:

Expand|Select|Wrap|Line Numbers
  1. function getcallingdir(){
  2.  
  3.   $callingdir= strstr($_SERVER[HTTP_REFERER],$_SERVER[HTTP_HOST]);
  4.   $callingdir = str_replace($_SERVER[HTTP_HOST],$_SERVER[DOCUMENT_ROOT],$callingdir);
  5.   $callingdir = trim(str_replace("index.html","",$callingdir));
  6.  
  7.   return $callingdir;
  8.  }
  9.  
Aug 27 '09 #3
hsriat
1,654 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. function get_calling_dir() {
  2.     $match = array();
  3.     if (preg_match("/([^/]+)(/index\.html)?$/", $_SERVER['HTTP_REFERER'], $match)) {
  4.         return $match[1];
  5.     }
  6.     return false;
  7. }
Do let me know if it doesn't work.
Aug 31 '09 #4
Works great thanks so much...
Sep 14 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: cwwilly | last post by:
Hello, Thanks for taking a look at this! Problem: I'm trying to pass multiple dynamic values between a slaveform and a masterform. The problem I'm having is on the slaveform I loop through...
8
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) {...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
2
by: Dan | last post by:
Here is the working script if anyone is interested. I was missing the else if. <script language="JavaScript"> <!-- function Trip_Time(Traffic_Results) { if...
4
by: news-server.tampabay.rr.com | last post by:
Hi, Below is a stock script I found which controls a framed environment. My problem is that if a URL has a query string attached, that string does not pass through. Can someone please let me...
1
by: colleen1980 | last post by:
Hi: Can any one please tell me that how to i pass the two textbox values in the new page. If i use the form action in the popup window page then the new page is open in the same popup window as i...
3
by: r_ahimsa_m | last post by:
Hello, I am learning JavaScipt. I have written some functions and I verified my code using http://www.jslint.com/ validator. I don't understand the problems it reports. Could you help me please...
3
by: swetha123 | last post by:
hello, I don't know how to use cookies please help me in this I am using the dream weaver cs4 I designed the navigation bar to my page using dream weaver cs4 navigation bar contains...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.