Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 04-08-2003, 03:29 PM   #1
Carlito
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Location: Texas
Posts: 856
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");
}

?>
Carlito is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-08-2003, 05:23 PM   #2
AkiraSS
Confirmed User
 
Join Date: Jan 2003
Location: ICQ: 17630227
Posts: 2,988
bump
AkiraSS is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-08-2003, 05:38 PM   #3
Lane
Will code for food...
 
Join Date: Apr 2001
Location: Buckeye, AZ
Posts: 8,496
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
__________________
Lane is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-08-2003, 05:53 PM   #4
MikeXAMO
Confirmed User
 
Join Date: Mar 2002
Location: Trailer Park
Posts: 660
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.
MikeXAMO is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-08-2003, 06:31 PM   #5
Carlito
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Location: Texas
Posts: 856
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 at 07:14 PM..
Carlito is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-08-2003, 06:37 PM   #6
Lane
Will code for food...
 
Join Date: Apr 2001
Location: Buckeye, AZ
Posts: 8,496
Quote:
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?
__________________
Lane is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-08-2003, 06:39 PM   #7
Carlito
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Location: Texas
Posts: 856
Yes.
Carlito is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-08-2003, 06:41 PM   #8
Carlito
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Location: Texas
Posts: 856
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
Carlito is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-08-2003, 06:49 PM   #9
Lane
Will code for food...
 
Join Date: Apr 2001
Location: Buckeye, AZ
Posts: 8,496
Quote:
Originally posted by Carlito
Yes.
then add this line at the end of the code:

unset($all_files);
__________________
Lane is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-08-2003, 06:55 PM   #10
Carlito
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Location: Texas
Posts: 856
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!
Carlito is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-08-2003, 06:57 PM   #11
Lane
Will code for food...
 
Join Date: Apr 2001
Location: Buckeye, AZ
Posts: 8,496
Quote:
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.
__________________
Lane is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-08-2003, 06:59 PM   #12
Carlito
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Location: Texas
Posts: 856
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!
Carlito is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.