473,943 Members | 2,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Newbie -- pass document.locati on to php

3 New Member
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.locati on from index.html, something like this:
<a href="./php/getimages.php?d ocument.locatio n" ....
(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 3826
dlite922
1,584 Recognized Expert Top Contributor
I still don't see your reasoning for why you wouldn't just redirect to that folder, but use php header("Locatio n: gallery/").

Am I understanding you wrong?



Dan
Aug 27 '09 #2
roadiee
3 New Member
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 Recognized Expert Top Contributor
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
roadiee
3 New Member
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
2588
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 multiple records and want two values depending on the row they select. slaveform: x=selected
8
8270
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) { document.location.href = document.location.href.substring(0, document.location.href.indexOf('#')) + '?' + newUrl; } else { document.location.href = document.location.href + '?' + newUrl; }
4
6329
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 the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
2
1689
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 (document.Traffic_Results.CIP_Diff.value == "point1") { document.Traffic_Results.display_time.value = "2:20";
4
4826
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 know if and hopefully how, it will be possible to carry a query string through? This first part here is in the default.asp framed page. <SCRIPT LANGUAGE="JavaScript">
1
9388
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 need to open the new page in the main page window with passing the two textbox parameters into the new page. Program opens the new page but dont know how to pass the two textboxes values into the new page name deceasedToday.asp Needs help in...
3
1399
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 and invoke http://www.jslint.com/ validator? Thanks for help. Here's the code: var reEmail = /^{1,40}@{1,70}$/; var reDate = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
3
2436
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 Home, Retail Contact Us
0
9970
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11535
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11126
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11299
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10662
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8220
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6309
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.