PHP Insight ~Geniuses

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Carlito
    Confirmed User
    • Dec 2001
    • 856

    #1

    PHP Insight ~Geniuses

    Hello,

    I have been working with this php code for a few hours and... cannot get one or two things to work. I was hoping some PHP genius here could correct and output something I can use.

    First of all, the directory thing does NOT work properly. When I select that directory it ONLY shows the files within that have extensions, NOT the directories. I ONLY want to show directories in my final. So I either need a regex that gets rid of the extensions, or I need something that loads the correct directory. I also need this to load TWO columns, one for pics and one for vids, when i place two seperate PHP codes inside of tables on my index.php, it shows the same output in both codes, this could be because of the missing 'closedir'. I did not include that because it don`t work right anyway.

    The goal of this code is to create a directory system where all I have to do is upload a directory with a certain file name and the code automatically lists it. The date part also works well so that it appears that the site was updated on whatever date, based on the /last modification/ date of a folder or file.

    Please if you make any contributions note where they need to be inserted into the existing code, I am new at this and really don`t fully understand the syntax yet.

    If anyone needs any further info or otherwise please just ask, i`ll be watching this topic today.

    Thanks!

    The code:

    <?php

    define('MAX_FILES', 365);

    $dp = opendir('/home/virtual/site16/fst/var/www/html/members/vids');

    if ($dp) {

    while( $item = readdir($dp) )
    {

    if ( $item hahahaha '.' || $item hahahaha '..' ) // replace the hahahaah that GFY creates with :
    continue;

    if ($mtime = @filemtime($item))
    $all_files[$mtime][] = $item;
    }
    krsort($all_files);
    foreach($all_files as $time=>$files)
    {
    for($i=0; $i < count($files); $i++)

    {
    $file = $files[$i];
    $date = date("m.d.y", $time);

    if (++$count > MAX_FILES)
    break;
    else
    printf('<font face="Trebuchet MS"
    size=2 color=#000000> <font face=tahoma

    size=1>[%s]</font> &nbsp;<a href="%s"
    class=hyperlink>%s</a></font><br>',
    $date, $file, $file); // Where it says %s is where the name of the output file resides.
    }
    }
    closedir($dp);
    } else {
    print("Could not open directory.\n");
    }

    ?>
  • AkiraSS
    Wemaxa.com
    • Jan 2003
    • 2989

    #2
    bump

    Comment

    • Lane
      Will code for food...
      • Apr 2001
      • 8496

      #3
      Code:
      define('MAX_FILES', 365);
      
      // changed below to save the path in a variable
      $dirpath = '/home/virtual/site16/fst/var/www/html/members/vids';
      
      $dp = opendir($dirpath);
      
      if ($dp) {
      
              while( $item = readdir($dp) )
              {
      
                      if ( $item hahahaha '.' || $item hahahaha '..' ) 
                             continue;
      
                      // added this to skip files and only get dirs
                      if (!is_dir($dirpath . '/' . $item))
                              continue;
       
                      // fixed error: path was not included
                      // changed the way items were added to the array, not sure it was an error.
                      if ($mtime = @filemtime($dirpath . '/' . $item))
                              $all_files[$mtime][count($all_files[$mtime])] = $item;
              }
              krsort($all_files);
              foreach($all_files as $time=>$files)
              {
                      for($i=0; $i < count($files); $i++)
      
                      {
                              $file = $files[$i];
                              $date = date("m.d.y", $time);
      
                              if (++$count > MAX_FILES)
                                      break;
                              else
                                      printf('<font face="Trebuchet MS"
      size=2 color=#000000> <font face=tahoma
      
      size=1>[%s]</font>  &nbsp;<a href="%s"
      class=hyperlink>%s</a></font><br>',  
      $date, $file, $file);  // Where it says %s is where the name of the output file resides.
                      }
              }
                  closedir($dp);
      } else {
              print("Could not open directory.\n");
      }

      i made the changes and fixed some stuff.
      from what i understood, u wanna display the directories inside the directory, and not the files..
      btw, because of they way you output the link, you need to place this script in the same folder that you are searching through..

      warning: untested code

      Comment

      • MikeXAMO
        Confirmed User
        • Mar 2002
        • 660

        #4
        This should get ya going, it will be easier to understand.

        (hopefully GFY wont hack it up, if it does I'll post it to http://www.xamo.com/carlito.html)

        ---------------------- START CODE --------------------


        <?
        define('MAX_FILES', 365);
        //$dir="/home/virtual/site16/fst/var/www/html/members/vids/";
        $dir="/www/internal/xamo.com/images/";
        $dp=opendir($dir);
        if($dp){
        while(false != = ($item = readdir($dp))){
        if ( $item = = '.' || $item = = '..' ){
        // Do nothing
        }else{
        if (file_exists($dir.$item)){
        $mtime=filemtime($dir.$item);
        $p=pathinfo($dir.$item);
        $ext=strtolower($p["extension"]);
        if($ext= ="gif" || $ext= ="jpg"){
        // its an image
        $all_files[$mtime][0] = $item;
        }
        if($ext= ="avi" || $exthahahaha"mov" || $exthahahaha"mpg"){
        // its a video
        $all_files[$mtime][1] = $item;
        }
        if(is_dir($dir.$item)){
        // its a directory
        $all_files[$mtime][2] = $item;
        }
        }
        }
        }
        krsort($all_files);
        echo "<table border=1 cellspacing=0 cellpadding=2>";
        echo "<tr><td><b>Date</b></td><td><b>Image</b></td><td><b>Video</b></td><td><b>Directory</b></td></tr>\n";
        foreach($all_files as $time=>$files){
        $_img = $files[0];
        $_vid = $files[1];
        $_dir = $files[2];
        $date = date("m.d.y", $time);
        if (++$count > MAX_FILES){
        break;
        }else{
        echo "<tr><td>[$date]</td><td>$_img</td><td>$_vid</td><td>$_dir</td></tr>\n"; // Where it says %s is where the name of the output file resides.
        }
        }
        echo "</table>";
        closedir($dp);
        }else{
        echo "Could not open directory.\n";
        }
        ?>

        -------------------------- END CODE -------------------
        Xamo Entertainment
        Xamo.com | EZSets.com

        ICQ: 9439118 MSN: mikeb [at] xamo.com Tollfree: 800-544-XAMO
        XXX CMS - Designed by Adult Webmasters, for Adult Webmasters.

        Comment

        • Carlito
          Confirmed User
          • Dec 2001
          • 856

          #5
          Thanks!

          You guys are great.

          I tried the latter code, it works well but needs a few additions to do exactly what I need. Thanks Mike!

          I used the first code, it dropped right in to what I needed and the rest is history. Only one more issue I did not see before... you can view the site here:



          Note how the second column called the same code from the first. In doing this I simply inserted the finished code into each table of the html. Apparently this is not correct, I am really not sure what to do about this... I tried using a php include in two spots calling two seperate files that go to the different directories... same error. I went ahead and changed the variables in the latter table to $dp1 rather than $dp, thinking maybe there was some interference... seems not.

          Once I get thru this i`ll be done, any further suggestions?

          Thanks!
          Last edited by Carlito; 04-08-2003, 06:14 PM.

          Comment

          • Lane
            Will code for food...
            • Apr 2001
            • 8496

            #6
            Originally posted by Carlito
            Thanks!

            You guys are great.

            I tried the latter code, it works well but needs a few additions to do exactly what I need. Thanks Mike!

            I used the first code, it dropped right in to what I needed and the rest is history. Only one more issue I did not see before... you can view the site here:

            http://www.xxxriot.com/members/

            Note how the second column called the same code from the first. In doing this I simply inserted the finished code into each table of the html. Apparently this is not correct, I am really not sure what to do about this... I tried using a php include in two spots calling two seperate files that go to the different directories... same error. I went ahead and changed the variables in the latter table to $dp1 rather than $dp, thinking maybe there was some interference... seems not.

            Once I get thru this i`ll be done, any further suggestions?

            Thanks!
            is this a php page?

            Comment

            • Carlito
              Confirmed User
              • Dec 2001
              • 856

              #7
              Yes.

              Comment

              • Carlito
                Confirmed User
                • Dec 2001
                • 856

                #8
                Now I see what you meant by the placing it in the same directory as the folders... I fixed that by assigning the path to the a href echo

                Comment

                • Lane
                  Will code for food...
                  • Apr 2001
                  • 8496

                  #9
                  Originally posted by Carlito
                  Yes.
                  then add this line at the end of the code:

                  unset($all_files);

                  Comment

                  • Carlito
                    Confirmed User
                    • Dec 2001
                    • 856

                    #10
                    yay!

                    Thanks for ending a whole weekend of work for me. Great job!

                    Do you code for contract also; or just food? Would definately be a useful addition to my contacts. Especially with the projects I have coming up.

                    Thanks a ton!

                    Comment

                    • Lane
                      Will code for food...
                      • Apr 2001
                      • 8496

                      #11
                      Originally posted by Carlito
                      yay!

                      Thanks for ending a whole weekend of work for me. Great job!

                      Do you code for contract also; or just food? Would definately be a useful addition to my contacts. Especially with the projects I have coming up.

                      Thanks a ton!
                      i barely have time to code for myself right now, so i dont really take jobs yet.

                      Comment

                      • Carlito
                        Confirmed User
                        • Dec 2001
                        • 856

                        #12
                        Ok, thanks a ton anyway, now I know where to check back in the future if I have a project and you have the time.

                        Thanks!

                        Comment

                        Working...