![]() |
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 : http://www.xxxriot.com/hah.gif 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> <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"); } ?> |
bump
|
Code:
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 |
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 ------------------- |
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! |
Quote:
|
Yes.
|
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
|
Quote:
unset($all_files); |
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! |
Quote:
|
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! |
| All times are GMT -7. The time now is 06:35 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123