Anyone know PHP?

Discussion in 'OT Technology' started by 95vr4, Oct 7, 2005.

  1. 95vr4

    95vr4 OT Supporter

    Joined:
    Oct 6, 2004
    Messages:
    2,513
    Likes Received:
    0
    Location:
    Weddington, NC
    I'm trying to actually learn how to write something like this instead of just uploading somebody elses script, can anyone good with PHP go through and explain what each command does :x:

    This script automatically takes pics from a folder and makes a gallery. I'm trying to set it up so our customers can upload pics of their cars and it will make a gallery for them instead of me manually doing it like this

    http://www.3sxperformance.com/customers.asp

    Thanks for any help

    example
    http://bonrouge.com/cheerspics.php


    <?php
    $dir="thumbs72/";
    $path="/home/myusername/public_html/bonrouge/".$dir;
    $handle=opendir($path);
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>CHEERS pics</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    <!--
    body {
    background-color:#fff;
    }
    ul, li {
    padding:0;
    list-style:none;
    }
    ul {
    position:relative;
    width:745px;
    margin:auto;
    background:url(cheerslogo500.jpg) 125px 70px no-repeat;
    border:1px solid #ccc;
    height:525px;
    padding-left:5px;
    }
    li {
    margin:5px 0;
    float:left;
    width:82px;
    height:54px;
    background-position:center center;
    background-repeat:no-repeat;
    }
    <?php
    $i=1;
    while ($file=readdir($handle)) {
    if (!preg_match("/^\.|\.\$/", $file) && ($file<>"error_log")) {
    echo "#pic$i {".(($i>9)? '
    margin-top:400px;' :'')."
    background-image:url($dir$file);
    }
    ";
    $i++;
    }
    }
    ?>
    a {
    display:block;
    height:54px;
    }
    a img {
    position:absolute;
    top:70px;
    left:125px;
    width:1px;
    border:0;
    }
    * html a:hover {
    display:block;
    height:53px;
    }
    a:hover img {
    width:500px;
    }
    a:active img,
    a:focus img {
    z-index:1;
    width:500px;
    }
    -->
    </style>
    </head>
    <body>
    <ul>
    <?php
    $i=1;
    $handle=opendir($path);
    while ($file=readdir($handle)) {
    if (!preg_match("/^\.|\.\$/", $file) && ($file<>"error_log")) {
    echo "<li id=\"pic$i\"><a href=\"#n\"><img src=\"/thumbs500/$file\" alt=\"pic$i\" /></a></li>
    ";
    $i++;
    }
    }
    ?>
    </ul>
    </body>
    </html>
     
  2. Riboflavin

    Riboflavin New Member

    Joined:
    Mar 30, 2005
    Messages:
    109
    Likes Received:
    0
    There is a lot more to that code than what you posted.
     
  3. 95vr4

    95vr4 OT Supporter

    Joined:
    Oct 6, 2004
    Messages:
    2,513
    Likes Received:
    0
    Location:
    Weddington, NC
  4. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    The code you posted just opens up a directory with the thumbnails inside using this:
    PHP:
     <?php
    $dir
    ="thumbs72/";
    $path="/home/myusername/public_html/bonrouge/".$dir;
    $handle=opendir($path);
    ?>
    This block of code reads the directory for the appropriate file.
    PHP:
    <?php
    $i
    =1;
    while (
    $file=readdir($handle)) {
    if (!
    preg_match("/^\.|\.\$/"$file) && ($file<>"error_log")) {
    echo 
    "#pic$i {".(($i>9)? '
    margin-top:400px;' 
    :'')."
    background-image:url(
    $dir$file);
    }
    "
    ;
    $i++;
    }
    }
    ?>
    This block of code loops through each picture and displays it on the web.
    PHP:
    <?php
    $i
    =1;
    $handle=opendir($path);
    while (
    $file=readdir($handle)) {
    if (!
    preg_match("/^\.|\.\$/"$file) && ($file<>"error_log")) {
    echo 
    "<li id=\"pic$i\"><a href=\"#n\"><img src=\"/thumbs500/$file\" alt=\"pic$i\" /></a></li>
    "
    ;
    $i++;
    }
    }
    ?>
    Additionally, you can find out what each function does by reading the PHP manual. http://www.php.net/manual/en/
    For future references, use the
    PHP:
     tags so it's a little bit more cleaner.  Thanks.
     
  5. 95vr4

    95vr4 OT Supporter

    Joined:
    Oct 6, 2004
    Messages:
    2,513
    Likes Received:
    0
    Location:
    Weddington, NC
    Thanks, that's exactly what I needed, the "for dummies" version :). Any ideas how I could use this to let a customer use their user name and password from our customers database and let them automatically generate their own cars pages? I was thinking maybe use something like asp upload.

    This is the way it is right now and I have to manually do each one

    http://www.3sxperformance.com/customers.asp

    Thanks again
     
  6. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    Yes, that would actually involve a more complex system, scripting, and a more complex database. There are various ways of doing it, but for someone who doesn't have much knowledge of PHP or SQL is definatly going to have a tough time doing it. It's not a beginner task.

    You'll need a script or system to handle users and authentication
    You'll need a script or system to handle the profile (each individual page) of each user.
    And you'll also need a script or system to handle the actual page itself. There is an equal amount of back end and front end work.

    The easiest way of doing this would be using one database that will handle everything.
     

Share This Page