Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 04-27-2005, 08:39 AM   #1 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
[PHP] Calling an image using variables

I have a page that called brewery.php on my site. It's laid out in total CSS with PHP variable scripts. I call this page into a parent page using the include comand.
Thus, a typical address would be www.arch13.com/index.php?id=main where main is the nested page being called into the parent template index.php.

Now I have a page called brewery.php that containes some new photography and I am looking at new ways of creating gallery's. The current PHP code being used on the page is:
Code:
	 
$id = $_REQUEST['id2'];
if(file_exists($id.".jpg")) {
echo "<img src='$id.jpg'>";
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='brewerysplash.jpg'>";
}
Yes it works, but it also creates ugly, ugly, ugly urls. Like http://www.arch13.com/index.php?id=b...ewery/brewery1
Is their a way to simplify this? What I'm looking for is a way to keep the url looking like www.arch13.com/index.php?id=brewery , and then have the id2= hidden, even though it was passed to get the picture it refrences. Perhaps like having brewery.php?id=1 where 1 is the first picture.
Am I making any sense?

The second question I suspect is easier.

the images for brewery.php are named brewery_x.jpg where x is the number of the image in order.
What code would allow id2=1 and call brewery_1.jpg? So that as the id # increased by 1, it just called the next image, assuming the brewery_ part?

Is there a way to go about this that does not require hand coding the image name prefix (brewery_) into the php code, to make such a script usefull in multipule areas?
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
Old 04-27-2005, 09:19 AM   #2 (permalink)
Insane
 
trache's Avatar
 
Quote:
www.arch13.com/index.php?id=brewery , and then have the id2= hidden, even though it was passed to get the picture it refrences. Perhaps like having brewery.php?id=1 where 1 is the first picture.
Am I making any sense?
The request method is either GET or POST, not both. You can do this however if memory serves me correctly, with register_globals turned on (which mashes the GET, POST, COOKIES, and ENV variables into their own variables), which is a very, very bad idea! Try to think of a way that you can use either GET or POST.

As to your second question:

Well, I'm not sure I understand the wording of the question correctly. Can you rephrase perhaps?

Above all, please please please make sure you validate your id1 or id2 variables! I don't see it, but perhaps you do have some validating code, so forget the following if you do:

If they're numbers, make sure they're numbers: use is_numeric(), is_float etc and perhaps if ($id1 > 0) to make sure it's not negative (if that's not what you're going for).

If you don't, someone could easily craft a way to exploit your program. If you're going to be including PHP files, do something like this:

Code:
$inc_files = array('main.php', 'blah.php');
if (in_array($id, $inc_files) == TRUE)
{

include($id);

}
else
{

include('default_page.php');

};
The code may not be correct, but hopefully you get the idea. Now users can't possibly go to any other page that is NOT in the array. You can easily load that array with values from just about anything.
__________________
"You looked at me as if I was eating runny eggs in slow motion." - Gord Downie of The Tragically Hip
trache is offline  
Old 04-27-2005, 09:46 AM   #3 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
Quote:
Originally Posted by trache
As to your second question:

Well, I'm not sure I understand the wording of the question correctly. Can you rephrase perhaps?

Above all, please please please make sure you validate your id1 or id2 variables! I don't see it, but perhaps you do have some validating code, so forget the following if you do:

If they're numbers, make sure they're numbers: use is_numeric(), is_float etc and perhaps if ($id1 > 0) to make sure it's not negative (if that's not what you're going for).

If you don't, someone could easily craft a way to exploit your program. If you're going to be including PHP files, do something like this:

Code:
$inc_files = array('main.php', 'blah.php');
if (in_array($id, $inc_files) == TRUE)
{

include($id);

}
else
{

include('default_page.php');

};
The code may not be correct, but hopefully you get the idea. Now users can't possibly go to any other page that is NOT in the array. You can easily load that array with values from just about anything.
I don't use the array becuase it's not worth it for the small scale of my site. The percentile chance of malicious code being injected by a user who uses my variable string to call his own page is incredibly small as the php code will only look as far as the root directory for the requested include file.
If your talking about some other type of exploit possability, please explain what you mean.

As for question 2;

Take the page
http://www.arch13.com/index.php?id=b...brewerycolor11

In that URL, I'm hating giving away my folder tree.
I'd like to craft code that wil allow me to say id2=11 and have it call the image mentioned above, so that the user cannot see the image path as the variable, but only
http://www.arch13.com/index.php?id=brewery&id2=11 instead.

As for question 1;
It's a moot point if question two can be answered in a way that address's hiding the directory tree.
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
Old 04-27-2005, 11:20 AM   #4 (permalink)
Darth Papa
 
ratbastid's Avatar
 
Location: Yonder
...But you want to be able to bring in images from any directory? Is that it?

You could write a nested array of directories and then refer to the directories by array index. But that's sort of fugly.

I suggest you use the oft-overlooked PATH_INFO field to pass the file location, rather than a query-string parameter.

In the url:
http://www.arch13.com/index.php/imgs...r11?id=brewery

You should end up in index.php with:

$_REQUEST[id] = "brewery"
and
$_SERVER[PATH_INFO] = "/imgs/brewery/brewerycolor11"

It's still a lengthy URL, but it's not carying a ton of extra info in the QUERY_STRING, and it looks (except for that ".php" in there) like any old URL to a file or directory.

PATH_INFO is great for hiding the fact that it's a dynamic page. I one time turned on CGI-EXEC on the root htdocs directory, put a Perl CGI in there called "pages", and called it with URLs like:

http://www.site.com/pages/product/1234.html

My "pages" script then spun out a page based on my "product" template with data from MySQL for item number "1234", and Google was none the wiser.
ratbastid is offline  
Old 04-27-2005, 12:20 PM   #5 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
Quote:
Originally Posted by ratbastid
...But you want to be able to bring in images from any directory? Is that it?
Exactly. I take photo's of different places a lot as part of my job. The goal here is that all images come from imgs/blah where blah is the folder named for the place. In this case it would be imgs/brewery. The php file that sits in the root is called brwery.php, and calls the images using the variable. The goal as a crude content managment system is that say I took pictures of a new abandoned building. Let's call it stockhouse. Then I open up the brewry page in my editor, change the descriptive text in the photo_nav div, and save it as stockhouse.php. Then I place all the images in a newly created imgs/stockhouse folder. index.php?id=stockhouse would call the new page, and the php code would pull the apropriot images.

I don't mind having to change a variable in the php code when I create the new page to point to the correct image folder, I just don't want the huge varaibe url. So a php page for each place (Client), that corrisponds to a sub-folder in imgs/. I can change the varaible on each page I make, I just don't want to show all my data in the URL.

Becuase the image is called using id2, I'd like to just name each image name_number and the script, having the imgs directory variable coded in when I made the page, would know that id2=1 means grab say stockhouse_1.jpg and diplay it in the image display area.

Having variable two simply equal a number looks a lot cleaner. Bonus points if in doing this, there is a way to not show anything besides the first variable. I don;t mind index.php?id=blah&id2=1 for example, but being able to hide varaible two all together to create arch13.com/index/php?id-blah without showing the other variables would be awsome.

As it may be obvious, I'm pretty clueless on varaible usage (or anything else) in PHP.

Quote:
I suggest you use the oft-overlooked PATH_INFO field to pass the file location, rather than a query-string parameter.

In the url:
http://www.arch13.com/index.php/imgs...r11?id=brewery

You should end up in index.php with:

$_REQUEST[id] = "brewery"
and
$_SERVER[PATH_INFO] = "/imgs/brewery/brewerycolor11"

It's still a lengthy URL, but it's not carying a ton of extra info in the QUERY_STRING, and it looks (except for that ".php" in there) like any old URL to a file or directory.

PATH_INFO is great for hiding the fact that it's a dynamic page. I one time turned on CGI-EXEC on the root htdocs directory, put a Perl CGI in there called "pages", and called it with URLs like:

http://www.site.com/pages/product/1234.html

My "pages" script then spun out a page based on my "product" template with data from MySQL for item number "1234", and Google was none the wiser.
Hmmm. Not trying to hide the page being dynamic from the search bots. Just trying to clean up the url and set up something that makes creating lots of these pages easier.
I don't want to show server paths at all. I just want arch13.com/index.php?id=blah where blah is the page they are at (This is how it currently works, allowing blah to just be a text file since it only needs to be parsed as part of the include) Looking at the url now, they go "Oh, I'm at the blah page of his site" since the format is easy to deduce.

The idea is that on this page, the little red box is navigation, and when the right arrow is clicked, the image advances to the next image. Clicking the back arrow cuases the obvious effect. (No clue how I'm going to do this either, but I try to go one step at a time when learning)

Not being trained in these things, I'm struggling to find the correct words to describe what I'm out for. Forgive me for being a little clueless.
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
Old 04-27-2005, 02:33 PM   #6 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
Let me join in this with a question:

You need http://www.arch13.com/index.php?id=brewery&id2=12345
to turn into a "brewery" page with image number 12345?

Or are you trying to hide id2 from the url and just show id=brewery ?

EDIT: I think I get the fact that you want to simplify the URL to hide the paths, but it's ok to have both id= and id2= in the url.

So I suggest (as posted by you earlier):
http://www.arch13.com/index.php?id=brewery&id2=12345

The code should be something like this:
PHP Code:
//constant:
define('IMAGE_PATH''img/');
//VALIDATE THE INPUT BEFORE THIS.
$filename=$_REQUEST['id'].'_'.$_REQUEST['id2'].'.jpg'  //turns index.php?id=brewery&id2=1 into brewery_1.jpg
$image_location=IMAGE_PATH.$filename  (turns it into 'img/brewery_1.jpg'
Then you can proceed to check for file_exists, and enter it into your code.
And you should validate your code as people could try to access your complete filesystem by requesting stuff like id=../../etc/passwd
(Depending on system setup this might work).
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)

Last edited by Silvy; 04-27-2005 at 02:47 PM..
Silvy is offline  
Old 04-27-2005, 02:40 PM   #7 (permalink)
Darth Papa
 
ratbastid's Avatar
 
Location: Yonder
If I were you, I'd make a record in MySQL for each image, and refer to an AUTO_INCREMENTing ID field in your $_REQUEST parameter. That's the simplest way I can think of to eliminate the complexity and filestructure-giveaway-ness of your current design. Maybe you could make yourself an upload page that would take the image, insert the record, and save the image to the appropriate directory?
ratbastid is offline  
Old 04-27-2005, 06:46 PM   #8 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
Quote:
Originally Posted by Silvy
I think I get the fact that you want to simplify the URL to hide the paths, but it's ok to have both id= and id2= in the url.

So I suggest (as posted by you earlier):
http://www.arch13.com/index.php?id=brewery&id2=12345

The code should be something like this:
PHP Code:
//constant:
define('IMAGE_PATH''img/');
//VALIDATE THE INPUT BEFORE THIS.
$filename=$_REQUEST['id'].'_'.$_REQUEST['id2'].'.jpg'  //turns index.php?id=brewery&id2=1 into brewery_1.jpg
$image_location=IMAGE_PATH.$filename  (turns it into 'img/brewery_1.jpg'
Then you can proceed to check for file_exists, and enter it into your code.
And you should validate your code as people could try to access your complete filesystem by requesting stuff like id=../../etc/passwd
(Depending on system setup this might work).
That's exactly the path I'm trying to find!

The url would be www.arch13.com/index.php?id=brewery&id2=1 for the brewery page, displaying image 1.
That's brilliant to use $_REQUEST['id'].'_'.$_REQUEST['id2'].'.jpg. How would this work into my current code?
I think it's something like this:

Code:
$id = $_REQUEST['id2'];
define('IMAGE_PATH', 'img/');
$filename=$_REQUEST['id'].'_'.$_REQUEST['id2'].'.jpg'  
$image_location=IMAGE_PATH.$filename 
if(file_exists($id.".jpg")) {
echo "<img src='$id.jpg'>";
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='brewerysplash.jpg'>";
}
Just one into the other, that way your php makes us of the $id = $_REQUEST['id2']; defined at the begining, right?

It looks right, but I don't know. Guess I'll try it when I get home from studio.
Thank you for understanding through my vague description!
I'll report back as soon as I've tested it later tonight.

(By the way, my server is set not to allow display of directories, so a file name would need to be guessed correctly to exploite the variable in the url, otherwise nothing would be displayed and the code would just insert the else when rendering the page.)

Ratbastid, I don't have a database to use. I have mysql on the hosting package, but have never even set it up as that's an additonal layer of learning required, and I seem to be trying very little the needs this kind of stuff.
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
Old 04-27-2005, 11:55 PM   #9 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
Quote:
Originally Posted by arch13
Ratbastid, I don't have a database to use. I have mysql on the hosting package, but have never even set it up as that's an additonal layer of learning required, and I seem to be trying very little the needs this kind of stuff.
Too be honest, a database is the most elegant solution for this kind of thing, but if I'm sensing the correct level of programming, then it's a little ways to go in terms of learning for you. But don't worry, once you get this script down, and you see how databases work sometime, then you'll re-write it in no time

As for the code, no it's not completely correct.
You are indeed using $_REQUEST['id2'] as you suggested (by calling it with $id), but not in the correct way (as it is now, your code would be looking for '1.jpg' and not 'img/brewery_1.jpg').
The code as (I think) it should be is this:

(I've tried to use as much of your code as possible to help you understand what's going on. I also added comments, but if it's not completely clear, please do ask! Check this code against yours above to see the differences, I couldn't find a good way to display the differences...)
Code:
/* Set up external variables */
$id = $_REQUEST['id'];
$id2 = $_REQUEST['id2'];

/*  This is the place for the "optional" sanitizing of the variables you got from the URL */

/* Set up constants */
// Note, we're not using constants much, but it helps getting used to them
define('IMAGE_PATH', 'img/');  // From now on we can use IMAGE_PATH, and it will substitute the string 'img/' for it.  If you ever change the images directory, then changing this constant is enough for your entire code.

/* setup complicated variables */
$filename=$id.'_'.$id2.'.jpg'     // Since we defined $id / $id2 to be the URL variables before, we can use them.  Saves typing, and makes it easier to read.
$image_location=IMAGE_PATH.$filename   // Becomes 'img/brewery_1.jpg' in our example

/* program flow  */
if(file_exists($image_location)) {    // We already "built" the location variable, no need to do it again ;)
echo "<img src='$image_location'>";   // Same here...
} elseif(file_exists($id.".php")) {  
include($id.".php");
} else {
echo "<img src='brewerysplash.jpg'>";
}
Notes:
  • When naming variables that represent values you got from the URL, be careful. Your code was confusing in that you set $id to be URL value id2
  • In that respect, to help read your code, it might help to name the variables "gallery" and "img_id" just so it is never unclear of which is which. Of course, it is not necessary, and for the sake of continuing this thread it might be better to leave it as-is for now.
  • Seperating the creation of the image path, instead of just using file_exists('img/'.$id.'.jpg) allows for easy manipulation in the beginning of the code while ensuring that any changes propagate nicely. Otherwise a decision to use, say, GIFs would require you to look up all references to .jpg and change them. In the code above only one line of code needs to be changed.
  • On that note, it's probably more elegant to have another variable "alternative_location" (or something like that) to define what file should be included if the image is not found (instead of "building" that in your program flow itself.
  • Once you get this down, and made it work (Code never works out-of-the-box )Try looking into sanitizing the input variables ($id / $id2) to make sure that no dots and slashes are in them. Better safe than sorry, and it's good practice.
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)
Silvy is offline  
Old 04-29-2005, 01:24 PM   #10 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
Quote:
Originally Posted by Silvy
(I've tried to use as much of your code as possible to help you understand what's going on. I also added comments, but if it's not completely clear, please do ask! Check this code against yours above to see the differences, I couldn't find a good way to display the differences...)
Code:
/* Set up external variables */
$id = $_REQUEST['id'];
$id2 = $_REQUEST['id2'];

/*  This is the place for the "optional" sanitizing of the variables you got from the URL */

/* Set up constants */
// Note, we're not using constants much, but it helps getting used to them
define('IMAGE_PATH', 'img/');  // From now on we can use IMAGE_PATH, and it will substitute the string 'img/' for it.  If you ever change the images directory, then changing this constant is enough for your entire code.

/* setup complicated variables */
$filename=$id.'_'.$id2.'.jpg'     // Since we defined $id / $id2 to be the URL variables before, we can use them.  Saves typing, and makes it easier to read.
$image_location=IMAGE_PATH.$filename   // Becomes 'img/brewery_1.jpg' in our example

/* program flow  */
if(file_exists($image_location)) {    // We already "built" the location variable, no need to do it again ;)
echo "<img src='$image_location'>";   // Same here...
} elseif(file_exists($id.".php")) {  
include($id.".php");
} else {
echo "<img src='brewerysplash.jpg'>";
}
Notes:
  • When naming variables that represent values you got from the URL, be careful. Your code was confusing in that you set $id to be URL value id2
  • In that respect, to help read your code, it might help to name the variables "gallery" and "img_id" just so it is never unclear of which is which. Of course, it is not necessary, and for the sake of continuing this thread it might be better to leave it as-is for now.
  • Seperating the creation of the image path, instead of just using file_exists('img/'.$id.'.jpg) allows for easy manipulation in the beginning of the code while ensuring that any changes propagate nicely. Otherwise a decision to use, say, GIFs would require you to look up all references to .jpg and change them. In the code above only one line of code needs to be changed.
  • On that note, it's probably more elegant to have another variable "alternative_location" (or something like that) to define what file should be included if the image is not found (instead of "building" that in your program flow itself.
  • Once you get this down, and made it work (Code never works out-of-the-box )Try looking into sanitizing the input variables ($id / $id2) to make sure that no dots and slashes are in them. Better safe than sorry, and it's good practice.
Okay, I tried your code and it parse errors badly. I see why though, so that's good that I'm understanding that much.

Here's how it's working (This will also address your first list point):
Main page index.php contains the following:
PHP Code:
$id $_REQUEST['id'];
if(
file_exists($id.".jpg")) {
echo 
"<img src='$id.jpg'>";
} elseif(
file_exists($id.".php")) {
include(
$id.".php");
} else {
echo 
"<img src='Brewerysplash.jpg'>";


The included page then has:
PHP Code:
$id $_REQUEST['id2'];
if(
file_exists($id.".jpg")) {
echo 
"<img src='$id.jpg'>";
} elseif(
file_exists($id.".php")) {
include(
$id.".php");
} else {
echo 
"<img src='brewerysplash.jpg'>";

So your suggestion does not work becuase there are two php scripts on different pages at play here.
index.php has the script with $id = $_REQUEST['id'] in it, while whatever page is included has the php code for $id = $_REQUEST['id2'].
That way, if a page included through id variable does not make use of id2, there is no id2 script in the included page. An example is my "main/about" page at www.arch13.com/index.php?id=main where the first script is in the template page that has all the tables (index.php), and the main.php page then has a script for id2 to call the left hand image.

So I guess what I'm searching for is a way to keep the index.php script intact, and sinply pass the id variable onto the second script so it can use it as above for id2?
Or would using your suggested page on the index.php page, and simply creating an anchor for id2 in any included page be more effeciant?
Am I making any sense?

hmmm. To put it another way, do I scrap the two scripts, on on each page with one for id and one for id2, and replace it with a single script on index.php, and create say echo ($id2.".jpg") on the brewery page where I want the image to be, or is it better to work with two php scripts, one on the index page addressing id, and one on whatever page id calls addressing id2?
With that second option, could the needed information be passed between the two seperate scipts addressing id's 1&2 so that your suggested code could work if used in the brewery page?

/Arch13's brain explodes
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
Old 04-29-2005, 02:33 PM   #11 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
Ok, I had this really long response ready, and I re-read your post to see wether I got all your questions, and I got confused



Let's try to narrow down the issues a little

index.php builds general page layout plus 1 of 3 things (load $id.jpg, load $id.php, load brewerysplash.jpg) correct?

$id.php does what exactly? (and is it the same for every $id? i.e. brewery.php, stable.php, garage.php)
(does it just echo a single image, or does it create buttons, or other stuff?)

In order to try to answer some questions for you:
- Can you call $_REQUEST['id2'] from within included files: yes
- Can you call variables from index.php from within included files: yes
- Can you disguise $_REQUEST['id2'] as $_REQUEST['id']: NO, or at least you shouldn't (but you can pass $id to the included files...)
- Is it better to split the files or build one big index.php? I don't know
(see my next post)

Hope this will settle some questions, so we can get to the good stuff
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)
Silvy is offline  
Old 04-29-2005, 02:39 PM   #12 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
NOTE: READ THIS FIRST
I wrote this response to Arch13's previous post.
I thought he was asking 2 questions:
- Should I include files dynamically?
- Is it possible for included files to use variables set in the URL?
This response tries to tackle those questions. But re-reading his post, I wasn't sure he was asking for this
So that's why I posted follow-up questions (my previous post).
But in an effort to speed things along (and in case he indeed did ask for this reponse), I will now post the original reply I wrote.

See this as more of an informational post, rather than continuing the discussion.

End note


I see your problem. (EDIT: I didn't )
Though using global variables should work on included pages.

BUT..... why would you?

What does the included page do? If the included page does the same thing everytime (i.e. display an image that the first script can guess itself), why would you include it, and not just build it in.

IMHO including files can have the following reasons:
- clearer code (large included libraries for example)
- seperate authors. No need to include other's code because it makes debugging difficult
- often-changing files (if the included files change often, or are perhaps changed by someone else)
- code in the included files is not always needed. (as seems to be your case. You include files dynamically).

Now the last point is only valid if the different included files (say brewery.php, stable.php, garage.php etc) vary in code or this difference in functionality is expected in the future
If the code is predictable (as your quoted second file seems to be), why not put it into your main index.php?

Your suggestion:
Quote:
Originally Posted by Arch13
Or would using your suggested page on the index.php page, and simply creating an anchor for id2 in any included page be more effeciant?
would then be the way to go.

If, however, you still want / need to variably include files, and hence need to pass the $_REQUEST['id2'] parameter to the include file, you should not need to do much.
On my installation this works out of the box. I just created 2 files (ugly code, but it works )
Save them in their suggested names, and try it out. One displays the value for 'id' (taken from the URL) and includes the second file. The second file prints the value of id2 which is also taken from the URL. In essence this proves that passing the values you need, works.

First file:
(include_test.php)
PHP Code:
<?php
echo '<pre>';
echo 
"include test \n";

echo 
'$_REQUEST[id] equals: '.$_REQUEST['id']." \n";
echo 
"Including file: \n";
include (
'included.php');
echo 
"passed including files \n";
?>
Second file:
(included.php)
PHP Code:
<?php
echo 'Inluded file thinks $_REQUEST[id2] equals: '.$_REQUEST['id2']."\n";
?>
Now if you call "include_test.php?id=foo&id2=bar" you should see this:
Code:
include test 
$_REQUEST[id] equals: foo 
Including file: 
Inluded file thinks $_REQUEST[id2] equals: bar
passed including files
I hope this clears things up a little in either case. I guess it's obvious I'm not sure why you dynamically include files, so I tried to help by giving that "reasons for including" list above.
Anyhow, unless your setup blocks it, passing URL variables to included files works automatically. (And so should so called 'global variables', so if you need to create a variable, you can "pass" it to included files as well. In fact, that's how my scripts usually load a bunch of settings, it includes a settings file which creates a whole bunch of global variables.)

Note: indeed I forgot two semicolons in my previous code, so it didn't parse. The above code was copy/pasted from the working files so they should work
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)
Silvy is offline  
Old 04-29-2005, 04:17 PM   #13 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
I'm going to take your posts one at a time, and the second post is going to be long as I'm going to include the html and php from my index page, and an example page that would be called as an include.

Quote:
Originally Posted by Silvy
Ok, I had this really long response ready, and I re-read your post to see wether I got all your questions, and I got confused



Let's try to narrow down the issues a little

index.php builds general page layout plus 1 of 3 things (load $id.jpg, load $id.php, load brewerysplash.jpg) correct?

$id.php does what exactly? (and is it the same for every $id? i.e. brewery.php, stable.php, garage.php)
(does it just echo a single image, or does it create buttons, or other stuff?)
Index.php is the template page. It is what is seen at www.arch13.com . It's the backround, navigation, etc. It's all built with html and css, it's just a php file to allow it to be parsed for the include script that includes the footer copyright and the main window content. It's the frame that displays in other words. You are right that it will do one of the three mentioned based on the url variables and if id=blah is a php or jpg file.
I like that functionality, and it took a while to figure it out with lots of help. The else is just to put something (brewerysplash.jpg) up should they try to request something that does not exist.

$id.php is whatever plaintext file I'm displaying in the templates content area. if you go to my front page, where brewerysplash.jpg is, that is the "content area". The point has always been seperating content from display. That way, many different types of content can be placed in that box based on what I want the viewer to see. Conversly, I can change the template, and not have to edit or change any of the included files.

There are areas where we get complicated. In my portfolio for example. Index.php calls p_gallery into the content area using $id, and then p_gallery call's portfolio_gal.php through $id2 to build the thumbnail table. In this case, $id and $id2 have othing to with one another besides doing similar actions (calling in another file via include)

Quote:
In order to try to answer some questions for you:
- Can you call $_REQUEST['id2'] from within included files: yes
- Can you call variables from index.php from within included files: yes
- Can you disguise $_REQUEST['id2'] as $_REQUEST['id']: NO, or at least you shouldn't (but you can pass $id to the included files...)
- Is it better to split the files or build one big index.php? I don't know
(see my next post)

Hope this will settle some questions, so we can get to the good stuff
The feeling I got was this. Right now index.php has the first $id php script in it's content area box. I need that to always work, regardless of what the included page has in it's coding. $id is how I choose what file to display there. $id2 is what I use when the included page also needs to include something.
I'm not trying to disguise on as the other.
I'm currently calling $_REQUEST['id2'] from the included file I caled using $id if I understand your first list point
Can I use the $id variable from the index page in the included pages php script? That's what I was trying to ask in less well phrased questioning.

So, On to the actual markup of index.php and brewery.php as maybe that will help you understand what I'm asking instead of me babbling
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
Old 04-29-2005, 04:43 PM   #14 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
So here is my index.php:

Code:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>Arch13 Architecture and Tactile Design</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Arch13 is a small design studio focused on Architectural Design and Historic Preservation.
We like working with our hands and finding solutions that aren't just 'off the shelf'" />
<meta name="robots" content="ALL" />
<meta name="author" content="Arch13 Design Studio" />
<meta name="publisher" content="Arch13" />
<meta name="subject" content="Arch13 Design Studio" />
<meta name="title" content="Arch13" />

<link href="css/global.css" rel="stylesheet" media="screen" type="text/css">
<link href="css/type.css" rel="stylesheet" media="screen" type="text/css">

</head>
<SCRIPT LANGUAGE="JavaScript" src="common/fadeitb.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!-- Idea by:  Nic Wolfe (Nic@TimelapseProductions.com) -->
<!-- Web URL:  http://fineline.xs.mw -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=300,left = 312,top = 234');");
}
// End -->
</script>
<body bgcolor="#181A25">

<table width="700" height="408" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #FFFFFF; width: 698px;">
  <tr bgcolor="#FFFFFF"> 
    <td width="28" height="25" bgcolor="#999999" class="navbars" cellpadding="0" cellspacing="0">&nbsp;</td>
    <td width="201" bgcolor="#999999" class="navbars" cellpadding="0" cellspacing="0"><font color="#FFFFFF"><a href="index.php" class="masthead">Arch13.com</a></font></td>
    <td width="439" height="25" bgcolor="#999999" class="navbars" cellpadding="0" cellspacing="0"><div align="right">Bryce 
        | Sonia</div></td>
    <td width="28" bgcolor="#999999" class="navbars" cellpadding="0" cellspacing="0">&nbsp;</td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td height="25" class="navbars" cellpadding="0" cellspacing="0">&nbsp;</td>
    <td height="25" class="navbars" cellpadding="0" cellspacing="0">Architecture/Design</td>
    <td height="25" class="navbars" cellpadding="0" cellspacing="0"><div align="right"><a href="index.php?id=main">About</a> 
        | <a href="index.php?id=recent">Recent Work</a> | <a href="index.php?id=contact">Contact</a> 
        | <a href="index.php?id=resume">Resum&eacute;</a> | <a href="index.php?id=p_gallery&id2=portfolio_gal">Portfolio</a></div></td>
    <td height="25" class="navbars" cellpadding="0" cellspacing="0">&nbsp;</td>
  </tr>
  <tr> 
    <td height="353" bgcolor="#CCCCCC"><div align="center" class="unnamed2"> 
        <p>&nbsp;</p>
      </div></td>
    <td height="353" colspan="2"cellpadding="0" class="contentbox"><div align="center">
        <?php 
$id = $_REQUEST['id'];
if(file_exists($id.".jpg")) {
echo "<img src='$id.jpg'>";
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='Brewerysplash.jpg'>";
} 
?>
      </div>
      <div align="center"></div></td>
    <td bgcolor="CCCCCC">&nbsp;</td>
  </tr>
</table>
<div align="center" class="footer"><br>
<A HREF="javascript:popUp('popup_copyright.php')" class="footer">
<?php include"footer.htm"; ?>
</A>
</div>
</body>
</html>
My class="contentbox" is my content display area. As you see, the php that calls $id is there so that depending on the url, it places the included file called in that box.

Now brewery.php:

Code:
<link href="css/global.css" rel="stylesheet" type="text/css" />
<link href="css/layout.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.wrapper {
	height: 480px;
	width: 640px;
	margin:0px auto;
	text-align:center;
	padding-top:0px;
	border:1px #fff;
}
.photo_image {
	height: 440px;
	margin: 0 0 0 0px;
	background-color:#BFCCE3;
	remove--->
	font-family: Verdana;
	font-size: 11px;
}
.photo_nav {
	height: 40px;
	margin:0 0 0 0px;
	text-align:left;
	padding:0px 0px 0px 5px;
	border-top:2px solid #ccc;
	background-color:#666;
	font-family: Verdana;
	font-size: 11px;
}
.photo_subnav {
	width: 55px;
	height: 40px;
	background-color:#660000;
	padding:0px 0px 0px 0px;
	float: left;
	color: #FFFFFF;
	}
-->
</style>
<div class="wrapper">
  <div class="photo_image">	
  <?php 
	 
$id = $_REQUEST['id2'];
if(file_exists($id.".jpg")) {
echo "<img src='$id.jpg'>";
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='brewerysplash.jpg'>";
} 
?>
</div>
  <div class="photo_nav">
    <div class="photo_subnav">< 1/12 ></div>
    Crasnton, RI - Built in 1853 as the Providence Trolley house. Used as the 
    repair shop and storage shed for trolleys until 1923 when the city shuttered 
    their traction car system. It was then converted to the Cranston Brewery under 
    which it operated until the company went under in the late 70's.</div>
  </div>
So here is the goal in a nutshell: Clean up the php coding to be more efficiant, and so that $id2=12345 instead of the name. Your previously suggested, parse failed script is hitting the nail on the head of intent there. Of course, that is only for this include page that I want it to work that way. In the case of www.arch13.com/index.php?id=p_gallery, I still need $id2 to work as it does currently. (when it doesn't, you'll notice that clicking that url defaults to a picture of a boiler on the left instead of a thumbnail table since the url didn't set an $id2)
The solution I'm searching for is something to use on all the building gallery pages. Brewery.php, stockhouse.php, etc.
So the url www.arch13.com/index.php?id=brewery will display the brewery.php file in the content box of the index.
Becuase I still need the code to work in way similar to currently on some pages, while the way we're discussing on others, I thought keeping the $id and $id2 scripts seperate was a good idea. But I know a lot less about clean code than you do.

I want to create a new set of pages, one for each building I document. On these pages, the solution I want is what we are discssuing.
So to comment on your script as suggested:

Code:
$id = $_REQUEST['id'];  //Can't we just get this from the script in index.php since that already defined it?
$id2 = $_REQUEST['id2'];

define('IMAGE_PATH', 'img/');  // Okay, I understand that this allows the code to place imgs/ in front of the image path

$filename=$id.'_'.$id2.'.jpg'     // Since we defined $id in the parent page (index.php), how to we pass it on to this php script on the included page?
$image_location=IMAGE_PATH.$filename   // Becomes 'img/brewery_1.jpg' in our example. That's exactly what I was thinking of.

if(file_exists($image_location)) {    
echo "<img src='$image_location'>";   // So this is what displays the picture dependong on the variable..
} elseif(file_exists($id.".php")) {  
include($id.".php");
} else {
echo "<img src='brewerysplash.jpg'>";
}
Am I loosing you at this point?
I really hope not

Can your suggested script be made to work while leaving the php script in index.php the same and just messing with the php script on the included page, or is this going to take a whole new appraoch?
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
Old 04-29-2005, 05:42 PM   #15 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
Warning, read the entire post, answer the last part first, it'll probably be the most relevant.

Quote:
Originally Posted by arch13
Index.php is the template page. It is what is seen at www.arch13.com . It's the backround, navigation, etc. It's all built with html and css, it's just a php file to allow it to be parsed for the include script that includes the footer copyright and the main window content. It's the frame that displays in other words. You are right that it will do one of the three mentioned based on the url variables and if id=blah is a php or jpg file.
I like that functionality, and it took a while to figure it out with lots of help. The else is just to put something (brewerysplash.jpg) up should they try to request something that does not exist.
Understood. And I agree.

Quote:
Originally Posted by arch13
$id.php is whatever plaintext file I'm displaying in the templates content area. if you go to my front page, where brewerysplash.jpg is, that is the "content area". The point has always been seperating content from display. That way, many different types of content can be placed in that box based on what I want the viewer to see. Conversly, I can change the template, and not have to edit or change any of the included files.
Right. So far we're on the same track. 3 files:
1 content ($id.php)
1 mostly structure (index.php)
1 layout, color etc (css)
Quote:
Originally Posted by arch13
There are areas where we get complicated. In my portfolio for example. Index.php calls p_gallery into the content area using $id, and then p_gallery call's portfolio_gal.php through $id2 to build the thumbnail table. In this case, $id and $id2 have othing to with one another besides doing similar actions (calling in another file via include)
This gets interesting. Do you want p_gallery to call $_REQUEST['id2'] directly? Or do you want index.php to set up a special variable for it?

Quote:
Originally Posted by arch13
The feeling I got was this. Right now index.php has the first $id php script in it's content area box. I need that to always work, regardless of what the included page has in it's coding. $id is how I choose what file to display there. $id2 is what I use when the included page also needs to include something.
I'm assuming you've got some way to generate the correct URL's (with the id2 and stuff).
Quote:
Originally Posted by arch13
I'm not trying to disguise on as the other.
I'm currently calling $_REQUEST['id2'] from the included file I caled using $id if I understand your first list point
Can I use the $id variable from the index page in the included pages php script? That's what I was trying to ask in less well phrased questioning.

So, On to the actual markup of index.php and brewery.php as maybe that will help you understand what I'm asking instead of me babbling
Actually 'disquise' is the wrong word. I meant wether you wanted the value of id2 put into variable $id for the included file.
Actually for that first list point I meant that $_REQUEST['id2'] should not be put into a variable $id if there is no specific reason. Because when you read through your code later, you might mistake $id coming from $_REQUEST['id']. I usually try to name my variables logically to make the code easier to understand.
Ofcourse if a script depends on the existance of $id. And the value for it is located in $_REQUEST['id2'], by all means do that.

On to the next post:
Quote:
Originally Posted by arch13
So here is my index.php:

My class="contentbox" is my content display area. As you see, the php that calls $id is there so that depending on the url, it places the included file called in that box.
Got it. Looks good.
Quote:
Originally Posted by arch13
Now brewery.php:
Say index.php is located in www/
Where is brewery.php located? (and if you had a choice, where do you want it to be after we're done?)
- in www/
- in www/brewery
- in www/imgs/brewery

The reason I'm asking is that it looks like all files are currently in the same directory. (judging by a quick glance through the code).
Then again, you mentioned paths in your URLs before, so this is indeed a problem we need to tackle. Apparently your index.php is in (say) www/
your images are in www/brewery/ (ex. www/brewery/brewery1.jpg)
Since we're hiding the path now, we need to decide where you want the middle-man (brewery.php, which essentially is the second file in the include-chain).

I'd suggest:
index.php does a file_exists('brewery.jpg') (so local to the index.php)
index.php then does a file_exists('brewery/brewery.php') (so in a sub-dir from index.php)
(and then the splash)
brewery.php looks in it's local directory for the images.
brewery.php looks in a subdir for the include
(and then the splash)
etc.
Quote:
Originally Posted by arch13
So here is the goal in a nutshell: Clean up the php coding to be more efficiant, and so that $id2=12345 instead of the name. Your previously suggested, parse failed script is hitting the nail on the head of intent there. Of course, that is only for this include page that I want it to work that way. In the case of www.arch13.com/index.php?id=p_gallery, I still need $id2 to work as it does currently. (when it doesn't, you'll notice that clicking that url defaults to a picture of a boiler on the left instead of a thumbnail table since the url didn't set an $id2)
The solution I'm searching for is something to use on all the building gallery pages. Brewery.php, stockhouse.php, etc.
So the url www.arch13.com/index.php?id=brewery will display the brewery.php file in the content box of the index.
Becuase I still need the code to work in way similar to currently on some pages, while the way we're discussing on others, I thought keeping the $id and $id2 scripts seperate was a good idea. But I know a lot less about clean code than you do.
-blush- thanks.
I think you'll find the above set up of file locations to be a good step towards your goal.


Note, about the code, I wrote the script to replace the code in index.php (hence some confusion there. This was my fault, as I thought it would reference the images directly. )
Given the mix-up, all your comments are correct.
Quote:
Originally Posted by arch13
I want to create a new set of pages, one for each building I document. On these pages, the solution I want is what we are discssuing.
So to comment on your script as suggested:
Right, and I suggest placing the PHP file of each building in a seperate directory with it's images. Cleans it up quite nicely. Plus if you ever (re)move an image set, the PHP file goes with it, all neat.

Quote:
Originally Posted by arch13
Am I loosing you at this point?
I really hope not

Can your suggested script be made to work while leaving the php script in index.php the same and just messing with the php script on the included page, or is this going to take a whole new appraoch?
Actually, you just got me back
With the above set up we can leave most of the files the way they are.
To be absolutely compatible with the current situation (but migrate to the file setup I mentioned earlier) change this in index.php:
Code:
$id = $_REQUEST['id'];
if(file_exists($id.".jpg")) {
echo "<img src='$id.jpg'>";
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='Brewerysplash.jpg'>";
}
In to:
Code:
$id = $_REQUEST['id'];
if(file_exists($id.".jpg")) {
echo "<img src='$id.jpg'>";
} elseif( file_exists( $id."/".$id.".php" ) {
include(  $id."/".$id.".php" 
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='Brewerysplash.jpg'>";
}
Essentially, I just added elseif( file_exists( $id."/".$id.".php" )
This checks wether a subdirectory exists with a php file.
Now all images are in www/brewery right?
put the brewery.php in there as well.
If the images in www/brewery are called brewery1.jpg and so on change
Code:
$id = $_REQUEST['id2'];
if(file_exists($id.".jpg")) {
echo "<img src='$id.jpg'>";
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='brewerysplash.jpg'>";
}
In to:
Code:
$base = 'brewery';   //only for images if they are called brewery1.jpg etc.
$id = $_REQUEST['id2'];
if(file_exists($base.$id.".jpg")) {
echo "<img src='$base.$id.jpg'>";
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='brewerysplash.jpg'>";
}
I added a "$base = " statement, and added $base to the 2 image searching and loading lines.
(if the images in www/brewery are called 1.jpg, 2.jpg etc you can leave the code as-is).

It should then work.
(forgetting all those things about coding practices, constants and other stuff, let's get it to work first )
Then we'll clean up the code.

This way, if I'm correct, all should work the same as it is now but for brewery. Brewery can now use shorter URLs
http://www.arch13.com/index.php?id=brewery&id2=1 should load up the page through index.php, which looks for brewery/brewery.php and includes it. Brewery.php then looks for brewery1.jpg, finds it and echo's the corresponding HTML.

Are we getting somewhere?

Btw, if there is a maximum post size on this forum, we should be reaching it pretty soon
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)
Silvy is offline  
Old 04-29-2005, 10:32 PM   #16 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
Last question first?
Your right, where getting close to the post size limit

Actually, big question's answer is we are definiatly getting somewhere
You are speaking in ways that make me sure you are understanding my strange questions.
I tried the code at the end ( www.arch13.com/index.php?id=brewery_test&id2=1 )
It doesn't work becuase the php file and images are in different folders. I'll address that in this post in a minute.
Now on to my befuddled responses.

Quote:
Originally Posted by Silvy
This gets interesting. Do you want p_gallery to call $_REQUEST['id2'] directly? Or do you want index.php to set up a special variable for it?
To see this in action, go see the portfolio page via the link on the navbar of my site. It's just a daisy chain of includes. Index.php--->p_gallery.php--->gal.php
what do you mean by special variable?
Is there another way than just using id and id2 like I'm doing? It's clean and simply currently, but I'm always for less complication.

Quote:
Looks good.

Say index.php is located in www/
Where is brewery.php located? (and if you had a choice, where do you want it to be after we're done?)
- in www/
- in www/brewery
- in www/imgs/brewery
index.php is in the root (we'll call it www/ for now)
right now brewery.php is also there. I don't like that. I want it to be in www/brewery with the images in www/imgs/brewery (I like having all images in a single folder for clarity)
images have always been there throughout our posts. This is part of my "don't show the path question".
How to have the images and php file in different folders without making long file paths out of the $id variables in the url.
Right now you'd have to type http://www.arch13.com/index.php?id=b...imgs/brewery_1 to see an image. That drives me crazy that the $id2 variable shows the file path to the image. That's why I'm looking to make it just $id2=12345 instead.

Quote:
The reason I'm asking is that it looks like all files are currently in the same directory. (judging by a quick glance through the code).
Then again, you mentioned paths in your URLs before, so this is indeed a problem we need to tackle. Apparently your index.php is in (say) www/
your images are in www/brewery/ (ex. www/brewery/brewery1.jpg)
Since we're hiding the path now, we need to decide where you want the middle-man (brewery.php, which essentially is the second file in the include-chain).

I'd suggest:
index.php does a file_exists('brewery.jpg') (so local to the index.php)
index.php then does a file_exists('brewery/brewery.php') (so in a sub-dir from index.php)
(and then the splash)
brewery.php looks in it's local directory for the images.
brewery.php looks in a subdir for the include
(and then the splash)
etc.
Exactly what I was just saying.
index.php in www/
brewery.php in www/brewery (we give it it's own folder becuase there is other data about the brewery that also needs to be grouped together. For example, a Plaintext page of historic data on the building that may be displayed as an include in index.php instead. Keeping like files together is the goal)
images in www/imgs/brewery

So I guess that what needs to happen is:
index.php does a file_exists ('brewery.php')
index.php then does a file exists ('brewery/brewery.php')
(Then the splash)
Brewery.php looks in a www/imgs/same name as php file for it's images
(and then the splash)

Quote:
Actually, you just got me back
With the above set up we can leave most of the files the way they are.
To be absolutely compatible with the current situation (but migrate to the file setup I mentioned earlier) change this in index.php:
...
In to:
Code:
$id = $_REQUEST['id'];
if(file_exists($id.".jpg")) {
echo "<img src='$id.jpg'>";
} elseif( file_exists( $id."/".$id.".php" ) {
include(  $id."/".$id.".php" 
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='Brewerysplash.jpg'>";
}
Essentially, I just added elseif( file_exists( $id."/".$id.".php" )
This checks wether a subdirectory exists with a php file.
Now all images are in www/brewery right?
put the brewery.php in there as well.
If the images in www/brewery are called brewery1.jpg and so on change
...
In to:
Code:
$base = 'brewery';   //only for images if they are called brewery1.jpg etc.
$id = $_REQUEST['id2'];
if(file_exists($base.$id.".jpg")) {
echo "<img src='$base.$id.jpg'>";
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='brewerysplash.jpg'>";
}
I added a "$base = " statement, and added $base to the 2 image searching and loading lines.
(if the images in www/brewery are called 1.jpg, 2.jpg etc you can leave the code as-is).
Okay.
The images are named as follows: brewery_x.jpg with x as the image number. In this case, saying $base = 'brewery_' would do the same thing but add the underscore, right?
Your code for index.php I understand completly. It accounts for each building having it's own folder of the same name as the page.
The code for the image display isn't correct though. As I mentioned above, the images are in www/imgs/brewery, not www/brewery. So the images and php file are in seperate directories. (The splash image is the only one I keep in the root)
when this gallery works, I'll create a splash image for this gallery to defualt to and place it in the www/imgs/brewery folder as well.


Quote:
It should then work.
(forgetting all those things about coding practices, constants and other stuff, let's get it to work first )
Then we'll clean up the code.

This way, if I'm correct, all should work the same as it is now but for brewery. Brewery can now use shorter URLs
http://www.arch13.com/index.php?id=brewery&id2=1 should load up the page through index.php, which looks for brewery/brewery.php and includes it. Brewery.php then looks for brewery1.jpg, finds it and echo's the corresponding HTML.

Are we getting somewhere?

Btw, if there is a maximum post size on this forum, we should be reaching it pretty soon
We are definatly getting somwhere.
So my next question is how do we account for brewery.php not being in the same folder as the images?
I assume we need to change the if(file_exists($base.$id.".jpg")) statment to reflect that it needs to check www/imgs/brewery for the files existance instead. Would it be if(file_exists(imgs/$base.$id.".jpg")) then?
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
Old 04-30-2005, 01:39 AM   #17 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
Not being disrespectful, but this is a case where the last part really is the most important so I removed most of the quote to get to the good stuff :

Quote:
Originally Posted by arch13
So my next question is how do we account for brewery.php not being in the same folder as the images?
I assume we need to change the if(file_exists($base.$id.".jpg")) statment to reflect that it needs to check www/imgs/brewery for the files existance instead. Would it be if(file_exists(imgs/$base.$id.".jpg")) then?
Very close! You see, the file_exists function looks for files relative to it's own location. Since brewery.php is in www/brewery/ the above file_exists will look for www/brewery/imgs/brewery_1.jpg
What we need is it to look for 1 directory higher than itself.

This can be done in one of 3 ways:
By using the full path of the file (so it looks for an absolute path, instead of a relative path.) (file_exists("/var/www/localhost/http/whatever/www/img/brewery_1.jpg")
By using a relative path, but to look one dir higher (file_exists("../imgs/brewery_1.jpg")
By using a global directive to point to the file locations.

This one should be relatively easy to grasp so we're going to do this the most elegant way (via the global constant).
Since all images are always located in www/imgs let's have index.php set the image_path constant:
(put this in the top-section of index.php, makes it easier to find later)
PHP Code:
<?php
define 
('IMAGE_FS_PATH''/var/www/img/');  //this should be the full filesystem path to your images
define ('IMAGE_WWW_PATH''img/');  //this should be the path relative to the URL.  (so it will expand to http://www.arch13.com/img/ etc)
?>
Then, change the $base statement, the first file_exists statement, and the echo statement in brewery.php to use the new paths:
PHP Code:
$base "brewery_";   //like you said
file_exists(IMAGE_FS_PATH.$base.$id.'jpg'//this expands into '/var/www/img/brewery_1.jpg
echo "<img src='".IMAGE_WWW_PATH.$base.$id".jpg'>";  this expands into imgs/brewery_1.jpgwhich will allow the browser to find it relative to "http://www.arch13.com" 
And leave the rest of the code as-is.

Does it work now?

Now, on to the rest of your post:
Quote:
Originally Posted by arch13
It doesn't work becuase the php file and images are in different folders.
Right, the above code should have fixed that. (in one of three ways)

In response to my question:
Quote:
Originally Posted by Silvy
This gets interesting. Do you want p_gallery to call $_REQUEST['id2'] directly? Or do you want index.php to set up a special variable for it?
Your answer:
Quote:
Originally Posted by arch13
To see this in action, go see the portfolio page via the link on the navbar of my site. It's just a daisy chain of includes. Index.php--->p_gallery.php--->gal.php
what do you mean by special variable?
Is there another way than just using id and id2 like I'm doing? It's clean and simply currently, but I'm always for less complication.
Right, I understand how p_gallery.php works. It calls $_REQUEST['id2'] to find out what it must do. The special variable I was talking about, was a part of advanced variable scope 101 Let's say for example that you want to re-use p_gallery for something else. Something where you don't know what's in the URL, so you expect another variable to be set.
index.php could set up a variable $included_file_parameters, which could then be read by whichever file is included (in our current code index.php would execute $included_file_paramters=$_REQUEST['id2']). This is neater (in my opinion) and more maintainable. But, for now, we should leave it as-is.

Quote:
Originally Posted by arch13
I want -brewery.php- to be in www/brewery with the images in www/imgs/brewery (I like having all images in a single folder for clarity)
images have always been there throughout our posts. This is part of my "don't show the path question".
Agreed.
Quote:
Originally Posted by arch13
So I guess that what needs to happen is:
index.php does a file_exists ('brewery.php')
index.php then does a file exists ('brewery/brewery.php')
(Then the splash)
Brewery.php looks in a www/imgs/same name as php file for it's images
(and then the splash)
Woa partner, easy there Yes, it can look for the "same name as php file" files, but for now we're hardcoding it in $base. That means you need to change it if you copy brewery.php to another some_other_building.php small inconvenience for now. But it is the reason we're using a dedicated $base variable, so if you copy the code, you just need to change $base="brewery_" to $base="some-other-building_" to make all of it work

I think we should have a working page now.
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)

Last edited by Silvy; 04-30-2005 at 01:49 AM..
Silvy is offline  
Old 04-30-2005, 02:36 PM   #18 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
Quote:
Originally Posted by Silvy
Not being disrespectful, but this is a case where the last part really is the most important so I removed most of the quote to get to the good stuff :



Very close! You see, the file_exists function looks for files relative to it's own location. Since brewery.php is in www/brewery/ the above file_exists will look for www/brewery/imgs/brewery_1.jpg
What we need is it to look for 1 directory higher than itself.

This can be done in one of 3 ways:
By using the full path of the file (so it looks for an absolute path, instead of a relative path.) (file_exists("/var/www/localhost/http/whatever/www/img/brewery_1.jpg")
By using a relative path, but to look one dir higher (file_exists("../imgs/brewery_1.jpg")
By using a global directive to point to the file locations.

This one should be relatively easy to grasp so we're going to do this the most elegant way (via the global constant).
Since all images are always located in www/imgs let's have index.php set the image_path constant:
(put this in the top-section of index.php, makes it easier to find later)
PHP Code:
<?php
define 
('IMAGE_FS_PATH''/var/www/img/');  //this should be the full filesystem path to your images
define ('IMAGE_WWW_PATH''img/');  //this should be the path relative to the URL.  (so it will expand to http://www.arch13.com/img/ etc)
?>
Then, change the $base statement, the first file_exists statement, and the echo statement in brewery.php to use the new paths:
PHP Code:
$base "brewery_";   //like you said
file_exists(IMAGE_FS_PATH.$base.$id.'jpg'//this expands into '/var/www/img/brewery_1.jpg
echo "<img src='".IMAGE_WWW_PATH.$base.$id".jpg'>";  this expands into imgs/brewery_1.jpgwhich will allow the browser to find it relative to "http://www.arch13.com" 
And leave the rest of the code as-is.

Does it work now?
Nope
I see two problems going on here, and I'm trying to see how we can fix them.
The first is actually straight foreward, but I almost didn't spot it.
We can't have $base= "brewery_"; like I suggested. It needs to be just "brewery" since the base statment is also used for finding the paths. Throwing in the underscore to makes the images work but makes the file paths not work.
Perhaps
file_exists(IMAGE_FS_PATH.$base._$id.'jpg';
But that screws up the code (I tried it). It parse errors like so:
Parse error: parse error, unexpected T_VARIABLE in /homepages/6/d93661089/htdocs/brewery_test.php on line 52
Line 52 was if(file_exists(IMAGE_FS_PATH.$base._$id.'jpg'; )) { , so that was a bad idea on my part to try.

Honestly, It's simplest for me to just change the image names to brewery1.jpg, since that should make the code work. I'll try it right now before continuing this post...
Nope

Okay, here are lines 49-59 of brewery.php that don't want to co-operate


PHP Code:
<?php 
$base 
'brewery_';   //only for images if they are called brewery1.jpg etc.
$id $_REQUEST['id2'];
if(
file_exists(IMAGE_FS_PATH.$base.$id.'jpg')) {  //this expands into '/var/www/img/brewery_1.jpg 
echo "<img src='".IMAGE_WWW_PATH.$base.$id'.jpg'>";  this expands into imgs/brewery_1.jpg, which will allow the browser to find it relative to "http://www.arch13.com" 
} elseif(file_exists($id.".php")) {
include(
$id.".php");
} else {
echo 
"<img src='brewerysplash.jpg'>";
}
?>
I set
PHP Code:
<?php
define 
('IMAGE_FS_PATH''/img/');  //this should be the full filesystem path to your images
define ('IMAGE_WWW_PATH''img/');  //this should be the path relative to the URL.  (so it will expand to http://www.arch13.com/img/ etc)
?>
Before the body html in index.php right under my javascripts, is that an okay position?

The system path is correct, as the php install is supposed to see my / as the root and works in all instances I've used it as such. It's not parse erroring, brewery_test is, so I assume it's working fine.

I have two copies of every image in the /imgs/brewery folder. One of each named brewery_1.jpg and one of each named brewery1.jpg. The file_exists is seeing neither right now.

Any suggestions?
The file I have been playing with is
www.arch13.com/index.php?id=brewery_test
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
Old 04-30-2005, 03:13 PM   #19 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
Quote:
Originally Posted by arch13
Nope
I see two problems going on here, and I'm trying to see how we can fix them.
The first is actually straight foreward, but I almost didn't spot it.
We can't have $base= "brewery_"; like I suggested. It needs to be just "brewery" since the base statment is also used for finding the paths.
Which paths?
I see the folllowing path info needed at some point:
- the path to the images (in brewery.php), this is set via the constant. $base, has no influence on that
- the path to brewery.php (in index.php), this is built out of $id= $_REQUEST['id'], $base has got nothing to do with it.
- the actual filename of the image. $base is used here, but not for the path, only for the image name. IMAGE_FS_PATH and IMAGE_WWW_PATH are used to get the directory structure.

So we build the full image path/name out of the following compontents:
constant: IMAGE_FS_PATH (= '/imgs/')
variable: $base (='brewery_')
variable: $id (='1');
string: '.jpg'
concatenating to: '/imgs/brewery_1.jpg' right?

Quote:
Originally Posted by arch13
Throwing in the underscore to makes the images work but makes the file paths not work.
Perhaps
file_exists(IMAGE_FS_PATH.$base._$id.'jpg';
But that screws up the code (I tried it).
Not a bad idea, but: the underscore is a seperate string. so put quotes(') around it, and concatenate it with dots (.), like so:
file_exists(IMAGE_FS_PATH.$base.'_'.$id.'jpg';
(but this is not necessary now, as $base can just contain the underscore)

Quote:
Originally Posted by arch13
Honestly, It's simplest for me to just change the image names to brewery1.jpg, since that should make the code work. I'll try it right now before continuing this post...
Nope
I think this may have to do with the path setting.
Try setting IMAGE_FS_PATH to the real filesystem path. (i.e. /var/www/etc)
this is needed on my setup, but it could very well different on yours.

Quote:
Originally Posted by arch13
I set
PHP Code:
<?php
define 
('IMAGE_FS_PATH''/img/');  //this should be the full filesystem path to your images
define ('IMAGE_WWW_PATH''img/');  //this should be the path relative to the URL.  (so it will expand to http://www.arch13.com/img/ etc)
?>
Before the body html in index.php right under my javascripts, is that an okay position?
As long as it is before you include files (brewery.php needs those 2 definitions).
I usually put them at the very top of my php files, as a sort of initialization. But so long as they're defined before they're used, it's fine
Quote:
Originally Posted by arch13
The system path is correct, as the php install is supposed to see my / as the root and works in all instances I've used it as such. It's not parse erroring, brewery_test is, so I assume it's working fine.
parse errors only mean that the syntax is wrong, it does not say anything about the values (in this case system paths) of variables.
I'm not sure what you mean by 'supposed to see my / as the root'.
Try setting IMAGE_FS_PATH to the FULL system path '/var/www/htdocs/whatever/' and set IMAGE_WWW_PATH to 'img/' (in the define statements in index.php)
(include the trailing slash on both constants)

Post the contents of index.php and brewery.php again, and any parse errors you got but couldn't fix. I think we're down to a few typos here or there.
(mainly in the paths or image names)

Btw: I see a unexpected T_CONSTANT_ENCAPSED_STRING error on your test page, check the line (53) for unmatched quotes (' or ") or a missing semi-colon( ; ) the semi-colon could also be missing on line 52.

Another note: the code above should be outputting HTML looking for images in http://www.arch13.com/imgs/brewery_1.jpg (and so on).
But looking for that URL gives me 404 errors. If the above URL should be correct, you might need to fix that first. If this URL to the image is not supposed to be correct, the code above needs fixing
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)
Silvy is offline  
Old 05-01-2005, 12:16 PM   #20 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
Quote:
Originally Posted by Silvy
Which paths?
I see the folllowing path info needed at some point:
- the path to the images (in brewery.php), this is set via the constant. $base, has no influence on that
- the path to brewery.php (in index.php), this is built out of $id= $_REQUEST['id'], $base has got nothing to do with it.
- the actual filename of the image. $base is used here, but not for the path, only for the image name. IMAGE_FS_PATH and IMAGE_WWW_PATH are used to get the directory structure.

So we build the full image path/name out of the following compontents:
constant: IMAGE_FS_PATH (= '/imgs/')
variable: $base (='brewery_')
variable: $id (='1');
string: '.jpg'
concatenating to: '/imgs/brewery_1.jpg' right?
The "www/imgs/same name as php file" path. I thought we were also using 'base' as the path after /imgs/.
I was under the impression that we were doing /imgs/$base/$base_12345.jpg as our formula.
This is most likely my mistake in understanding.

Also, this is where we are going wrong and the script is dying.
The images are located in /imgs/brewey/brewery_1.jpg. Each building has an image folder in /imgs/ , and a folder for their .php file and other info files in /.
For now, the brewery.php is just in the local root, and that shouldn't be a problem for what we're doing. If that is causing a problem, let me know and I'll get on creating the /brewery folder for the files already.
Brewery images brewery_1.jpg through brewery_12.jpg are all located in /imgs/brewery/.

Quote:

Not a bad idea, but: the underscore is a seperate string. so put quotes(') around it, and concatenate it with dots (.), like so:
file_exists(IMAGE_FS_PATH.$base.'_'.$id.'jpg';
(but this is not necessary now, as $base can just contain the underscore)
/Smacks head against wall
"Syntax, syntax, syntax!"

Quote:

I think this may have to do with the path setting.
Try setting IMAGE_FS_PATH to the real filesystem path. (i.e. /var/www/etc)
this is needed on my setup, but it could very well different on yours.
I'm going to stick phpinfo.php in the root of my site after lunch so I can actually see what my full server paths are. I have never bothered to use them, as most scripts have always 'magicaly' worked just using my root as an absolute path.


Quote:

As long as it is before you include files (brewery.php needs those 2 definitions).
I usually put them at the very top of my php files, as a sort of initialization. But so long as they're defined before they're used, it's fine

parse errors only mean that the syntax is wrong, it does not say anything about the values (in this case system paths) of variables.
I'm not sure what you mean by 'supposed to see my / as the root'.
Try setting IMAGE_FS_PATH to the FULL system path '/var/www/htdocs/whatever/' and set IMAGE_WWW_PATH to 'img/' (in the define statements in index.php)
(include the trailing slash on both constants)

Post the contents of index.php and brewery.php again, and any parse errors you got but couldn't fix. I think we're down to a few typos here or there.
(mainly in the paths or image names)

Btw: I see a unexpected T_CONSTANT_ENCAPSED_STRING error on your test page, check the line (53) for unmatched quotes (' or ") or a missing semi-colon( ; ) the semi-colon could also be missing on line 52.
I'll post brewery.php and index.php at the bottom of this message
I played around trying to edit and understand through experimentation when I got the parse errors, so it's probably all types of screwed up now.


Quote:
Another note: the code above should be outputting HTML looking for images in http://www.arch13.com/imgs/brewery_1.jpg (and so on).
But looking for that URL gives me 404 errors. If the above URL should be correct, you might need to fix that first. If this URL to the image is not supposed to be correct, the code above needs fixing
Your right, it's that the script is looking in the wrong place.

Thanks for your patience on this Silvy, have I mentioned you kick ass?
(But ohhhh, wait till you see my next silly question )

Index.php:

Code:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>Arch13 Architecture and Tactile Design</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Arch13 is a small design studio focused on Architectural Design and Historic Preservation.
We like working with our hands and finding solutions that aren't just 'off the shelf'" />
<meta name="robots" content="ALL" />
<meta name="author" content="Arch13 Design Studio" />
<meta name="publisher" content="Arch13" />
<meta name="subject" content="Arch13 Design Studio" />
<meta name="title" content="Arch13" />

<link href="css/global.css" rel="stylesheet" media="screen" type="text/css">
<link href="css/type.css" rel="stylesheet" media="screen" type="text/css">

</head>
<SCRIPT LANGUAGE="JavaScript" src="common/fadeitb.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!-- Idea by:  Nic Wolfe (Nic@TimelapseProductions.com) -->
<!-- Web URL:  http://fineline.xs.mw -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=300,left = 312,top = 234');");
}
// End -->
</script>
<?php
define ('IMAGE_FS_PATH', '/img/');  //full filesystem path to your images
define ('IMAGE_WWW_PATH', 'img/');  //this should be the path relative to the URL
?> 
<body bgcolor="#181A25">


<table width="700" height="408" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #FFFFFF; width: 698px;">
  <tr bgcolor="#FFFFFF"> 
    <td width="28" height="25" bgcolor="#999999" class="navbars" cellpadding="0" cellspacing="0">&nbsp;</td>
    <td width="201" bgcolor="#999999" class="navbars" cellpadding="0" cellspacing="0"><font color="#FFFFFF"><a href="index.php" class="masthead">Arch13.com</a></font></td>
    <td width="439" height="25" bgcolor="#999999" class="navbars" cellpadding="0" cellspacing="0"><div align="right">Bryce 
        | Sonia</div></td>
    <td width="28" bgcolor="#999999" class="navbars" cellpadding="0" cellspacing="0">&nbsp;</td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td height="25" class="navbars" cellpadding="0" cellspacing="0">&nbsp;</td>
    <td height="25" class="navbars" cellpadding="0" cellspacing="0">Architecture/Design</td>
    <td height="25" class="navbars" cellpadding="0" cellspacing="0"><div align="right"><a href="index.php?id=main">About</a> 
        | <a href="index.php?id=recent">Recent Work</a> | <a href="index.php?id=contact">Contact</a> 
        | <a href="index.php?id=resume">Resum&eacute;</a> | <a href="index.php?id=p_gallery&id2=portfolio_gal">Portfolio</a></div></td>
    <td height="25" class="navbars" cellpadding="0" cellspacing="0">&nbsp;</td>
  </tr>
  <tr> 
    <td height="353" bgcolor="#CCCCCC"><div align="center" class="unnamed2"> 
        <p>&nbsp;</p>
      </div></td>
    <td height="353" colspan="2"cellpadding="0" class="contentbox"><div align="center">
        <?php 
$id = $_REQUEST['id'];
if(file_exists($id.".jpg")) {
echo "<img src='$id.jpg'>";
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='Brewerysplash.jpg'>";
} 
?>
      </div>
      <div align="center"></div></td>
    <td bgcolor="CCCCCC">&nbsp;</td>
  </tr>
</table>
<div align="center" class="footer"><br>
<A HREF="javascript:popUp('popup_copyright.php')" class="footer">
<?php include"footer.htm"; ?>
</A>
</div>
</body>
</html>
brewery_test.php: (i'll change it's name back when it works)

Code:
<link href="css/global.css" rel="stylesheet" type="text/css" />
<link href="css/layout.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.wrapper {
	height: 480px;
	width: 640px;
	margin:0px auto;
	text-align:center;
	padding-top:0px;
	border:1px #fff;
}
.photo_image {
	height: 440px;
	margin: 0 0 0 0px;
	background-color:#BFCCE3;
	remove--->
	font-family: Verdana;
	font-size: 11px;
}
.photo_nav {
	height: 40px;
	margin:0 0 0 0px;
	text-align:left;
	padding:0px 0px 0px 5px;
	border-top:2px solid #ccc;
	background-color:#666;
	font-family: Verdana;
	font-size: 11px;
}
.photo_subnav {
	width: 55px;
	height: 40px;
	background-color:#660000;
	padding:0px 0px 0px 0px;
	float: left;
	color: #FFFFFF;
}
.spacer {
background-color:#666;
width: 10px;
height: 40px;
float:left;
}
-->
</style>
<div class="wrapper">
  <div class="photo_image"> 
<?php 
$base = 'brewery_';   //only for images if they are called brewery1.jpg etc.
$id = $_REQUEST['id2'];
if(file_exists(IMAGE_FS_PATH.$base.$id.'jpg')) {  //this expands into '/var/www/img/brewery_1.jpg 
echo "<img src='".IMAGE_WWW_PATH.$base.$id'.jpg'>";  this expands into imgs/brewery_1.jpg, which will allow the browser to find it relative to "http://www.arch13.com" 
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='brewerysplash.jpg'>";
}
?>
  </div>
  <div class="photo_nav">
    <div class="photo_subnav">< 1/12 ></div>
    Crasnton, RI - Built in 1853 as the Providence Trolley house. Used as the 
    repair shop and storage shed for trolleys until 1923 when the city shuttered 
    their traction car system. It was then converted to the Cranston Brewery under 
    which it operated until the company went under in the late 70's.</div>
  </div>
Edit
Added www.arch13.com/phpinfo.php . Take a look if you need any of that info.
My path looks to be /homepages/6/d93661089/htdocs on the server.
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever

Last edited by arch13; 05-01-2005 at 12:24 PM..
arch13 is offline  
Old 05-02-2005, 03:56 AM   #21 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
Quote:
Originally Posted by arch13
I was under the impression that we were doing /imgs/$base/$base_12345.jpg as our formula.

Also, this is where we are going wrong and the script is dying.
The images are located in /imgs/brewey/brewery_1.jpg. Each building has an image folder in /imgs/ , and a folder for their .php file and other info files in /.
For now, the brewery.php is just in the local root, and that shouldn't be a problem for what we're doing. If that is causing a problem, let me know and I'll get on creating the /brewery folder for the files already.
Brewery images brewery_1.jpg through brewery_12.jpg are all located in /imgs/brewery/.
Ok.
So $base is indeed necessary to find the path in /imgs/ we will need to use it twice. Once for the path, once for the filename, as you suggested earlier.

Quote:
Originally Posted by arch13
Thanks for your patience on this Silvy, have I mentioned you kick ass?
(But ohhhh, wait till you see my next silly question )
You're very welcome!
(and don't hesitate to post silly questions, but if there too silly post them in Tilted Nonsense )

Ok, we have still have the following issues:
- the /imgs/brewery/ lookup
- the fact that brewer_test.php has a different name than what index.php is looking for
- the fact that even though we want to have brewery.php in a seperate dir, it isn't now.

Let's solve the last 2 first:
(I understand you want to keep your current brewery.php as a backup, so we'll work around it)
- make a new dir www/brewery (for all your non-image brewery files)
- copy brewery_test.php to that dir and name it brewery.php

Add 2 lines to index.php:
Code:
$id = $_REQUEST['id'];
if(file_exists($id.".jpg")) {
echo "<img src='$id.jpg'>";
} elseif(file_exists($id.'/'.$id.'.php')){ //add this line
include($id.'/'.$id.'.php');   //add this line too
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='Brewerysplash.jpg'>";
}
(I added the first elseif clause)
That should at least allow index.php to find brewery/brewery.php and fall back to /$id.php for all others

Now to look up the correct images:
Change the following line in index.php:
Code:
define ('IMAGE_FS_PATH', '/homepages/6/d93661089/htdocs/img/');
change brewery_test.php: (which is now called brewery/brewery.php!!)
Change some lines here:
Code:
$base = 'brewery';   //CHANGED  (removed _ )
$id = $_REQUEST['id2'];
if(file_exists(IMAGE_FS_PATH.$base.'/'.$base.'_'.$id.'jpg')) {  //CHANGED added $base.'/'.  and .'_'
echo "<img src='".IMAGE_WWW_PATH.$base.'/'.$base.'_'.$id.".jpg'>";  //CHANGED added same as the line above, watch for correct quotes!
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='brewerysplash.jpg'>";
}
(I added $base, '/', and '_' to find the images in the correct path.)

Ok, I wonder what the effect of these changes is.
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)
Silvy is offline  
Old 05-02-2005, 10:46 AM   #22 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
Ya know, are you a teacher Silvy? You should be.
This url still isn't working though:
http://www.arch13.com/index.php?id=brewery&id2=11

I killed off the brewery.php in the local root, so we know that your new lines in the index.php did the trick. It's looking in /brewery for the page when given $id=brewery.
So now it's down to a single problem I guess.
I changed the image paths in the begining of index.php to:
Code:
define ('IMAGE_FS_PATH', '/homepages/6/d93661089/htdocs/imgs/');  //full filesystem path to images
define ('IMAGE_WWW_PATH', 'imgs/');  // path relative to the URL
It looks right to me (And I see where you got the full system path from phpinfo.php
The code in brewery.php itself looks like this:

Code:
$base = 'brewery';   //CHANGED  (removed _ )
$id = $_REQUEST['id2'];
if(file_exists(IMAGE_FS_PATH.$base.'/'.$base.'_'.$id.'jpg')) {  //CHANGED added $base.'/'.  and .'_'
echo "<img src='".IMAGE_WWW_PATH.$base.'/'.$base.'_'.$id.".jpg'>";  //CHANGED added same as the line above, watch for correct quotes!
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
echo "<img src='brewerysplash.jpg'>";
}
I'm guessing that the problem lies in here somewhere.
My question is, why isn't $id2 showing brewery_11.jpg in the url I gave at the begining of htis post?
It seems as the though the problem is with the image paths in some way.
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
Old 05-02-2005, 11:13 AM   #23 (permalink)
Insane
 
trache's Avatar
 
Quote:
My question is, why isn't $id2 showing brewery_11.jpg in the url I gave at the begining of htis post?
It seems as the though the problem is with the image paths in some way.
Quote:
if(file_exists(IMAGE_FS_PATH.$base.'/'.$base.'_'.$id.'jpg'))
You're missing a period before "JPG" -- your IF statement will ALWAYS be false!

Use the var_dump(), print_r() functions at any point in time to see the contents of a variable. It may help.
__________________
"You looked at me as if I was eating runny eggs in slow motion." - Gord Downie of The Tragically Hip

Last edited by trache; 05-02-2005 at 11:17 AM..
trache is offline  
Old 05-02-2005, 11:27 AM   #24 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
Quote:
Originally Posted by trache
You're missing a period before "JPG" -- your IF statement will ALWAYS be false!
.
Good catch!
Works perfectly now!
Awsome

So my next question is just a genral question. (I told you this was comming Silvy )
On that page there is a red box with <1/12>
I think why that's there is pretty straightforward. I want to figure how using php and javascript, I can use that to scroll through the images.
I suspect that a combo of php and swap.js to change the numbers is the way to go, but I always want opinions when getting in over my head
I figure that I can create 12 gifs, 1/12, 2/12, etc in the font I like that is not web freindly, and have swap.js swap them out as needed. The question is, how to create a system that allows the user the see the images using php?
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
Old 05-02-2005, 11:49 AM   #25 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
Quote:
Originally Posted by trache
You're missing a period before "JPG" -- your IF statement will ALWAYS be false!
Whoops, my bad. Good of you to spot that!

Quote:
Originally Posted by arch13
So my next question is just a general question.
On that page there is a red box with <1/12>
I think why that's there is pretty straightforward. I want to figure how using php and javascript, I can use that to scroll through the images.
I figure that I can create 12 gifs, 1/12, 2/12, etc in the font I like that is not web freindly, and have swap.js swap them out as needed. The question is, how to create a system that allows the user the see the images using php?
I don't know what swap.js is, you got that from somewhere?

What I would do, personally, is:
in brewery.php:
- find out how many pictures there are in the gallery (/imgs/brewery/)
- load a list of them in Javascript
- display < current_id / total_number > in the lower left corner.
- attach eventhandlers to the left and right brackets (< >)
Those (javascript) eventhandlers will replace the image with the previous and next images respectively.

I don't really see a neat way of doing the < 1/12 >, 2/12, 3/12 etc with image files though, either it's a lot of hassle doing it dynamically via PHP (create the image files on-the-fly) or force every gallery to have at least, and at most 12 images.

With my setup it doesn't do image pre-loading, meaning the browser will not download the image until it is needed, causing a delay between the click and the showing of the image. (Perhaps swap.js is supposed to pre-load images?)
I know image pre-loading is possible, I just haven't looked into it.

Quote:
Originally Posted by arch13
Ya know, are you a teacher Silvy? You should be.
Nope, I'm not, but I appreciate the compliment!
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)

Last edited by Silvy; 05-02-2005 at 12:21 PM..
Silvy is offline  
Old 05-02-2005, 08:18 PM   #26 (permalink)
Insane
 
trache's Avatar
 
Perhaps it's just me, but a vast number of people surf with JavaScript turned off for security reasons if not for annoying tricks webmasters play with JavaScript.

Consider trying to use some form of CSS to roll the images.
__________________
"You looked at me as if I was eating runny eggs in slow motion." - Gord Downie of The Tragically Hip
trache is offline  
Old 05-03-2005, 09:39 PM   #27 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
Well the most important thing is trying to make the <>'s work.
The idea being that a script is used that gives the $id2 list of images as an array ($id2=1-12),
such that each click of > adds +1 to the $id2 and every < does -1.

It seems equally possible in javascript and php, The whole display the # image thing is secondary. I'm also going to keep looking around for scripts that already do this in some way that may deliver a solution.

Given the framework we set up in this thread (Which is very important to me ), what suggestion might anyone have about how to integrate the ability to navigate through the buttons?

Also, Trache, How could this be acheived through CSS while fiting into the framework of $id2=1 calls brewery_1.jpg?
I'm real interested in that if it's a funtional possibility that can interact with the url variable framework.
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
Old 05-04-2005, 02:54 AM   #28 (permalink)
Insane
 
trache's Avatar
 
You could write the CSS file and link it inside your webpage dynamically, or you could write the styles out dynamically when and where you need them.

I believe there are a a:hover , a:visited, a, etc selectors that you could apply to an HREF that change its behaviour.

It's just a thought though. You may want JavaScript to be enabled before anyone could use the site; ultimately it's up to you.
__________________
"You looked at me as if I was eating runny eggs in slow motion." - Gord Downie of The Tragically Hip
trache is offline  
Old 05-04-2005, 03:20 AM   #29 (permalink)
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
As far as I know CSS is not meant for, nor capable of modifying, activating or defining URL's Meaning that CSS cannot be used to run through the images.

CSS is used to define styles, HTML is used to define structure, and you need a programming language to do anything but the most basic functionality. So either JavaScript, Flash, PHP, etc

Note: I think Trache meant that CSS can be used to insert an image (statically) into a page (for example, a background for the body, or a table).
CSS cannot however change the image once it is there.
To change the image, you need to reload the page, with a CSS file that uses a different image in the same place.
Personally, I think that this is not such a nice way of switching images.
/end Note

I agree with Trache's comments on javascript security and common annoyances, but I don't know what the statistics are for users with javascript enabled/disabled.
To be most compatible, a server-side solution is best. In your case: generating all pages with PHP.
Brewery.php would then compose a list of all images, output the page with the current image (id2), and depending on where that image is in the list, display the x/12 and < > things.
The brackets < > would then directly link back to a new page with id2+1 or id2-1.
The downside compared to JavaScript is the fact that the complete page will be reloaded for each image. The plus side is that all gallery logic is server-side and in the same language, making maintenance/debugging etc easier.
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)
Silvy is offline  
Old 05-05-2005, 06:54 PM   #30 (permalink)
Loves my girl in thongs
 
arch13's Avatar
 
Location: North of Mexico, South of Canada
Quote:
Originally Posted by Silvy
I agree with Trache's comments on javascript security and common annoyances, but I don't know what the statistics are for users with javascript enabled/disabled.
To be most compatible, a server-side solution is best. In your case: generating all pages with PHP.
Brewery.php would then compose a list of all images, output the page with the current image (id2), and depending on where that image is in the list, display the x/12 and < > things.
The brackets < > would then directly link back to a new page with id2+1 or id2-1.
The downside compared to JavaScript is the fact that the complete page will be reloaded for each image. The plus side is that all gallery logic is server-side and in the same language, making maintenance/debugging etc easier.
That is exactly what I'm thinking of Silvy
I guess I should start a new thread (or not if we're still going for longest single post records )
Is this a realitively easy approach? I don't mind the server load since the site does not have heavy traffic. I'm more concerened with good presentation and good code that can be used long term.

How do I go about this (Arch13 figures he may be getting some sort of bill from Silvy soon )
__________________
Seen on an employer evaluation:

"The wheel is turning but the hamsters dead"
____________________________
Is arch13 really a porn diety ? find out after the film at 11.
-Nanofever
arch13 is offline  
 

Tags
calling, image, php, variables


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 01:23 PM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62