Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question PHP Photo Gallery

    I am in the process of building a photo gallery.

    The site will have a lot of galleries with about 15 pictures at each.

    For obvious reasons, I do not want to build a separate html page for each picture.

    Imagine a gallery page like this:

    There are numbers below the picture from 1 to 15 - leading to other images.

    Is it possible that when I click one of these number-links, 'ONLY' the new image will load (without loading the rest of the page, and thus letting me get away with one page for each 'gallery' instead of one page for each 'image'.)

    Thanks!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Eh, I don't quite follow you.
    First, I was under the impression you are looking for a way to display a larger picture, clicking on the link to bring up a page with only the one picture. But now I'm thinking you want to click the image and replace just that picture with a new one, leaving the other 14 intact. Can you clarify?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Let me clarify:

    Here is the typical photo gallery page:

    http://www.fiscalstudy.com/photo-gal...gentina-11.php

    You click on the menu below the picture (I mean the numbers) in order to load a new picture.

    However, when you do that, a new page loads.

    I just want to click on a number, but I want just the new pic to load, not the whole page.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Oh I see. Ok, this isn't something that php can do - remember its server side, so it recieves the request, parses and fullfills it, and sends back its response. Php's job is done.
    You have a few options to do this, you can use javascript and probably an XML method of somesorts, an inline frame, or a hidden iframe with the use of javascript. Another option is to use CSS to cover each level of this using z-index and altering it using javascript. Its tricky, but possible. Php alone however cannot do this.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Looks like it is not an easy task!

    Thanks...


  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Your welcome.
    The CSS task isn't too tough, but you have to be willing to allow the page to refresh itself due to javascript off browsers. Obviously you can use the query string to identify the top level z-index is you want, but its trickier to control this than it seems. This is due to browser quirks, some browsers will allow usage of negative z-index, some will not. Because of this, you have to explicitly set the z-index for each level of depth display.
    IMO, the trouble it will take to use javascript and CSS to control the depth of your images isn't worth it. Instead your better off using a query string to pass the requested image and reload the page. You know how thats done correct? If not, you will need many a html pages, which I'm sure you don't want
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    New Coder
    Join Date
    Sep 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ssskaya, it is possible to make such a gallery, and it is not too difficult. There's multiple solutions, as already mentioned, javascript or php or even css. I'll give you some links. Javascript is fast as soon as the pictures are loaded. So, say you load the page, all pics are loaded. Then navigating through them is fast. However, js has it's drawbacks. With some ultra progressive css it's also possible to achieve the effect you want. However, the risk of making some mistakes or having some browser-problems is larger with a css only solution. So I think a PHP solution would be the best.
    A good php article about using php to include different pages or different sections in one page is here:
    http://www.digital-web.com/articles/easypeasy_php_2/. An example is given here:
    http://www.digital-web.com/extras/ea...p?id=brownbear
    Now, that exact same code can be used to include images in the page. Take a look at that article and the example files you can download there, and if you encounter problems, return here and ask

  • #8
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have modified it a bit, and have made it work on my server.

    Great!

    Now let me see if I can make it work in a ore complex template.

    Thanks!

  • #9
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have made it all, and it worked exactly as I wanted it to.

    I have one more question.

    I am not that good at PHP, so I could not manage to put variables in the php code.

    Could you please take a look at the code below and tell me what I am doing wrong?

    Thanks!

    Code:
    <?php
    ob_start();
    $variable = ABC;
    ?>
    
    <?php
    // Define our array of allowed $_GET values
    $pass = array('$variable_01','$variable_02','$variable_03','$variable_04','$variable_05','$variable_06','$variable_07','$variable_08','$variable_09','$variable_10','$variable_11');
    
    // Include our image, based on the $_GET parameter:
    if (in_array($_GET['id'], $pass)) {
    print '<img src="http://www.url.com/im/photo_gallery/' . $_GET['id'] . '.jpg" alt="$variable Photo Gallery" /><br />';
    } 
    // Otherwise use intro image:
    else {
    print '<img src="http://url.com/im/photo_gallery/$variable_01.jpg" alt="$variable Photo Gallery" /><br />';
    }
    ?>
    
    <?php
    // If the page is allowed, include it:
    if (in_array($_GET['id'], $pass)) {
    include ('http://www.url.com/photo_gallery/$variable/' . $_GET['id'] . '.php'); 
    }
    // If there is no $_GET['id'] defined, then serve the homepage:
    elseif (!isset($_GET['id'])) {
    include ('http://www.url.com/countries/$variable.php'); 
    }
    // If the page is not allowed, send them to an error page:
    else {
    // This send the 404 header
    header("HTTP/1.0 404 Not Found");
    // This includes the error page
    include ('http://www.url.com/er_docs/404.php');
    }
    ?>

  • #10
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have made it all, and it worked exactly as I wanted it to.

    Thank you all so much.

    I have one more question.

    I am not that good at PHP, so I could not manage to put variables in the php code of the gallery mentioned at the above link.

    Could you please take a look at the code below and tell me what I am doing wrong?

    Thanks!

    Code:
    <?php
    ob_start();
    $variable = filename;
    ?>
    
    <?php
    // Define our array of allowed $_GET values
    $pass = array('$variable_01','$variable_02','$variable_03','$variable_04');
    
    // Include our image, based on the $_GET parameter:
    if (in_array($_GET['id'], $pass)) {
    print '<img src="http://www.url.com/photo_gallery/' . $_GET['id'] . '.jpg" alt="$variable Photo Gallery" /><br />';
    } 
    // Otherwise use intro image:
    else {
    print '<img src="http://url.com/photo_gallery/$variable_01.jpg" alt="$variable Photo Gallery" /><br />';
    }
    ?>
    
    <?php
    // If the page is allowed, include it:
    if (in_array($_GET['id'], $pass)) {
    include ('http://www.url.com/photo_gallery/$variable/' . $_GET['id'] . '.php'); 
    }
    // If there is no $_GET['id'] defined, then serve the homepage:
    elseif (!isset($_GET['id'])) {
    include ('http://www.url.com'); 
    }
    // If the page is not allowed, send them to an error page:
    else {
    // This send the 404 header
    header("HTTP/1.0 404 Not Found");
    // This includes the error page
    include ('http://www.url.com/404.php');
    }
    ?>
    Last edited by ssskaya; 09-18-2005 at 09:23 PM.

  • #11
    New Coder
    Join Date
    Sep 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    try to change this:
    PHP Code:
    $pass = array('$variable_01','$variable_02','$variable_03','$variable_04'); 
    to this:
    PHP Code:
    $pass = array('variable_01','variable_02','variable_03','variable_04'); 
    Those $ are not neccessary. I'm sure it must work then, on my local system it did. Good luck.

  • #12
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I am not sure you understood me.

    If I put the filenames in the array, it surely will work.

    But I want to set a variable at the beginning as in:

    $variable = filename;

    ...and thus be able to put '$variable' instead of the 'filename'.

    However, doing so, the script did not work.

    I do not have a clue why.

  • #13
    New Coder
    Join Date
    Sep 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Aha, ok. Then we misunderstood eachother. Could you explain then what you want to accomplish? What do you want to do with the variables? There are lots of possibilities with arrays.
    If I understand what you want to do, maybe I or someone else can help.

  • #14
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Drop your quotations in order to evalute the php variables themselves.
    Why not just create this as a script that reads a directory, goes to specified image by numerical index, and go from there? Probably be a lot easier to do it that way, easy for expansion, so long as you make sure that nobody can put any files in there (ie, move it above your webroot).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #15
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Dropped quotes and still doesnt work.

    I dont really want to change this in a radical sense because it worked and I am not that good at php.

    I just want to add a variable as in $variable = filename and can't understand why it doesn't work with the way I posted above. It must be a simple mistake I guess..


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •