itssami
May 2 2006, 09:31 AM
| | For example,i have a directory , which has 3 sub directories a,b and c...and i have some files in all subdirectories.. is it possible that i can display the latest added files to any of sub directory a,b, or c.?i think i will have to use sort by date function but how it should be done that it compares the files of all the subdirectories directories ? |
Reply
mole2k9
May 2 2006, 01:14 PM
QUOTE(itssami @ May 2 2006, 09:31 AM)  For example,i have a directory , which has 3 sub directories a,b and c...and i have some files in all subdirectories.. is it possible that i can display the latest added files to any of sub directory a,b, or c.?i think i will have to use sort by date function but how it should be done that it compares the files of all the subdirectories directories ?
add this to the previous script, it doesn't check sub dirs but you can do sub dirs one at a time, CODE else if($file != '.' && $file != '..') {
$narray[$i]=$file; $i++;
//check for a / at the end of the path add one if not there if(substr($path, -1)!='/') { $path .= '/'; }
if(filemtime($path.$file)>$n) { $n = filemtime($path.$file); $newestname = $file; }
} }
rsort($narray);
for($i=0; $i<sizeof($narray); $i++) { echo "<a href=".chr(34).$path.$narray[$i].chr(34).">".$narray[$i]."</a><br/>";
}
echo $newestname;
Reply
itssami
May 2 2006, 08:42 PM
Hey..I think this doesnot display the entries by date.. i want that the latest added file in any directory should appear at upper..and then others lower by date of adding..the following function displays the files by alphabetically.. QUOTE(mole2k9 @ May 2 2006, 01:14 PM)  add this to the previous script, it doesn't check sub dirs but you can do sub dirs one at a time, CODE else if($file != '.' && $file != '..') {
$narray[$i]=$file; $i++;
//check for a / at the end of the path add one if not there if(substr($path, -1)!='/') { $path .= '/'; }
if(filemtime($path.$file)>$n) { $n = filemtime($path.$file); $newestname = $file; }
} }
rsort($narray);
for($i=0; $i<sizeof($narray); $i++) { echo "<a href=".chr(34).$path.$narray[$i].chr(34).">".$narray[$i]."</a><br/>";
}
echo $newestname;
Reply
Spectre
May 2 2006, 10:19 PM
Try something like this. It's not perfect, and I only wrote and tested it very quickly, but it's a start: CODE <table width="100%"> <tr> <td width="90%"><strong>File</strong></td> <td width="10%"><strong>Last Modified</strong></td> </tr> <?php
$files = array(); $directories = array('.');
for( $i=0;$i<count($directories);$i++ ) { $path = $directories[$i]; $directory = opendir($path); while( $contents = readdir($directory) ) { if( $contents != '.' && $contents != '..' ) { $item = $path . '/' . $contents; if( is_dir($item) && !in_array($item, $directories) ) { $directories[] = $item; } else { // // Note that if you wanted to sort the files by the time // they were created rather than modified, you would use // the function filectime() rather than filemtime() here. // $filetime = filemtime($item); while( isset($files[$filetime]) ) { $filetime++; } $files[$filetime] = $item; } } } closedir($directory); } krsort($files); $files_k = array_keys($files); for( $i=0;$i<count($files);$i++ ) { echo '<tr>' . "\n"; $filetime = $files_k[$i]; $file = $files[$filetime]; echo '<td style="font-size:10px;">' . $file . '</td>' . "\n"; echo '<td style="font-size:10px;">' . date('d-M-Y H:i', $filetime) . '</td>' . "\n"; echo '</tr>' . "\n"; }
?> </table>
Reply
WindAndWater
May 2 2006, 11:02 PM
It looks like someone already answered you, but here's an alternative implimentation that allows you to specify the folders you want sorted. I'm not sure which one you'll prefer. CODE <?php function dirList($dir) { $results = array(); $handle = opendir($dir); while($file = readdir($handle)) if ($file != '.' && $file != '..') $results[] = array($file, filemtime($dir . $file)); closedir($handle); return($results); } function reorderByDate($first, $second) { return($first[1] < $second[1]); }
/* Please only change the following line of code */ /* Directory names *must* end with a "/" */ $listOfDirs = array("folder1/", "folder2/"); $results = array(); foreach($listOfDirs as $dir) $results = array_merge($results, dirList($dir)); usort($results, "reorderByDate"); /* Displays the files -- change this if you want them to display differently */ foreach($results as $file) echo $file[0] . "<br />\n"; ?>
Reply
itssami
May 3 2006, 07:49 AM
Thank you very much for both of you guys to help me.. both of them works... but they just display the file names..and date..i want to give the hyperlink to the file also , so that when some one clicks on any of the file , it opens that file directly..(these functions just prints the names of the files.) thank you once again QUOTE(WindAndWater @ May 2 2006, 11:02 PM)  It looks like someone already answered you, but here's an alternative implimentation that allows you to specify the folders you want sorted. I'm not sure which one you'll prefer. CODE <?php function dirList($dir) { $results = array(); $handle = opendir($dir); while($file = readdir($handle)) if ($file != '.' && $file != '..') $results[] = array($file, filemtime($dir . $file)); closedir($handle); return($results); } function reorderByDate($first, $second) { return($first[1] < $second[1]); }
/* Please only change the following line of code */ /* Directory names *must* end with a "/" */ $listOfDirs = array("folder1/", "folder2/"); $results = array(); foreach($listOfDirs as $dir) $results = array_merge($results, dirList($dir)); usort($results, "reorderByDate"); /* Displays the files -- change this if you want them to display differently */ foreach($results as $file) echo $file[0] . "<br />\n"; ?>
Reply
Similar Topics
Keywords : displaying, latest, added, files, subdirectories
- Ipb Latest Activity Mod
where can i download this from? (14)
Need Some Help In File Browser
listing all sub folders and files in them. (8) Hey I want to create a very simple file browser, so that, it reads all the sub-folders which are
places in a directory, and the files inside the sub-folders (It reads only files inside sub-folders
and list them in simply. ) Also, it creates a directory (any name) inside each sub folder. My
Following code reads on the files inside the main directory, it does not read the files inside the
sub-folders.. I appreciate any help. CODE <? $path = "./"; $dir_handle =
@opendir($path) or die("Unable to open $path"); whil....
Download Script For Mp3 Files
(0) Hello, I'm looking for a download script for sound files (e.g. mp3, avi, wma, and other ones).
i have found a few download scripts but they would not work for sound files for some reason. also
this will not be used for allowing downloading of illegal or riped music, what i will be using this
script for is i'm making a site for my church and the pastor wants to be able to recored the
services and then have me upload them to the site so that the church members can download them for
what ever reason. If some one could tell me how to make one or could show me a plac....
Displaying 10 Records Per Page
(5) how to display 10 messages per page? CODE <?php
include("config/config.inc.php");
include("config/dbcon.php"); include("checksession.php");
if(isset($_POST['action'])){ $gname =
$_POST['gname']; $gemail = $_POST['mail'];
$gmsg = $_POST['gmsg']; $date =
date("m.d.y"); $sql = "insert into tblguestbook "; $sql ....
Displaying Date And Time (gmt+8)
(5) how to display date and time (gmt+8)? any help would be appreciated.....
Grabt Access To My Protected Files
grabt access to my protected files (2) Hi all, I am sure all of you are great programers but First i am no code programmer i am just
trying to learn to run my sites, will the problem is i got a code from the web to protect my files
,1st i want to know how to work it out then i will try other things but can't let it go without
a fight thanx all php: CODE <?php if ( ! defined( 'myname' )
) { print "You cannot access this file directly."; exit(); }
customer data here ?> now i can't access my files what is the meth....
Security Issue Writing Files
Security issue writing files (1) Hi, first, sorry about my english. i am a beginner with php and i have some question about writing
files using php in a shared hosting. is a risk?, use database to store data is a better way? i just
want make an interface (in php) that write the data in a .html extension file to show to everybody
the html page and just the php interface is to the content manager. thanks in advance ....
Displaying Your Phone Number On A Wap Site
(3) I have a wap site elitezone.co.za and what i want to add is a code to the index page that displays
your operator and phone number. Does any one know the coding for this function if so please show me
here. Help will appriacated. Topic title modified. ....
How To Display The Latest Forum Post On Main Page
(4) Hey does anyone know how to display the latest forum post on the main page of a website? I'm new
to PHP and have no idea what to do. Thanks in advance!....
[php]simple Flat File Text Manipulator
Example on how to use forms to write to files in PHP (3) I made a simple flat file text editor, that can show you probably how simple it is to use forms with
php and write that data to file. This example has 2 files, submit.php, and postit.html. Submit.php
is used to write title, and some text, and add html tags, and paragraph tags where new paragraphs
are. Here's the file with comments. I think that HTML really doesn't need some more
explaining. CODE Title: <br /> <input type="text"
name="title" size="53"> <br /> Text: <br />
<textarea nam....
Reading Files From Directory To Array, And Using $_get To Get Them
Simple way to manage lot's of files (2) Some user posted a similar problem i had when i tried to figure out how to update content on my
website in less work as possible. This is just part of the "big" plan i have for my site but it can
be helpfull to you guys if you like FlatFile. I hope that mod's don't mind me posting the
same code here and on their forums, couse if they do i'll delete it from their forums
/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> So
here's the situation. Let's say you have a folder called 'myfilesdirectory' on your
s....
Forms, Text Files, And Php For A Signature Generator.
Help a little. (1) Hello everyone! I am in need of some code a for a signature generator I am making. I am using
BuffaloHELP's code for the php file, now I am trying to improve that code by making a form in a
html file that will have the user say what is on the sig! But now, I need help getting the form
data that is posted by the user to get into that sig! There is a file, sig.txt, where that tells
the php file what text will go on the sig. But how can I make the form data in the html file go into
the text file so it will go onto the sig? You might want to read BuffaloHELP&....
Writing To Files And Such
(3) Ok lets say i have a config.php file, i want to edit something without open it, i know every line
number and that, now how would i do this? I will show you a example: CODE <?php
$CONFIG['user'] = 'root';
$CONFIG['server'] = 'localhost';
$CONFIG['pass'] = '******';
$CONFIG['db'] = '******';
$CONFIG['install'] = '1';
$CONFIG['lang'] ....
Files Required?
(5) I want to learn php and I am already on the first steps to doing it. I have set up my server using
easyPHP as well as XAMPP which is a package containing FileZilla, Apache and MySQL. Other than
easyPHP, XAMPP and MySQL, what other softwares are required to be set up for me to successfully
learn how to program with PHP?....
Displaying Files Of A Directory
(2) I want to display the contents of a directory.. i have the following code.. It gives the output in
one column only... like file1 file2 file3 file4 . . . . . Since there are lot of files so this
column gets very long..i want to display the x number of files in each column.. like if there are 22
files.. then file 1 file 11 file 21 file 2 . file 22 file 3 .. . . . file 10
file 20 This was just an example..I know it can be done by using but i dont know how to do it
with loop. Please help me. QUOTE $dir = './'; $handle =....
Logging Dowload Files From Your Server Onto A Html File
(1) Well, i had the idea of logging the downloads from my web in a html file few weeks ago, and i solved
it with a lil php page included in my homepage. You could name the links with a name like
"download.php?file=filename.ext" and then, in the download.php put the next code: (well you put
the html and head and body tags if u want, i only write the php here) CODE <? if
(isset($_GET['file']))
$file=$_GET['file']; //so it gets the GET data from url
(file=filename.ext); $ip=$_SERVER[....
How To List Files In A Directory + Subdirectory And Then Use Them.
(8) So lets say i have folders called friends and work in a folder called pics. how would i make a
function that lists the files in those folderscalled images kinda like this: CODE
$directory = "./" function listfiles($directory) { //here should go the
script to list the files in those directories. so that i can continue to work with them. like for
example if there were images it would list all the images and i could write a script to make a
thumb of them and then save it into a thumb folder(not asking for all of that). but how w....
Directory Files Displaying
(5) I have many files in a directory..I want to create a page , like A B C D E F ..... when some one
click on A , it should display all the files starting from letter A , and when clicks on B , it
should show all the files in that directory starting from B , and so on... I have no idea how to
display the files of the directory iin that way. Kindly assist me......
How To Sort Files Of A Directory using Php
(11) The following code displays the files of folder...but they are displaced by the order of adding... i
want to sord the files / folders alphabetically and sord by accending order and by decending
order.. can some one help me. $path = ""; $dir_handle = @opendir($path) or
die("Unable to open $path"); echo "Directory Listing of $path "; while($file =
readdir($dir_handle)) { if(is_dir($file)) { continue; } else
if($file != '.' && $file != '..') { echo " $fi....
What Kind Of Files Are .lib
(2) I want to know , if we use some pre-made php script , there are often many files with other
extension..i have been watching many times some files names ".lib" . what kind of files these are
... there's written C/C++ inline file.. why these kinds of files are needed in php scripts.. and
are there some replacements for it ? (So that we can do things without it ?)... for example im
pasting the coding of a file.. ban.lib ..i want to ask, why it is .lib file..why it cant be .php....
CODE <? function file2str($p){if($p=="") retur....
Here's A Nice And Interesting Way To Make Comments
In your php files (9) We all know that when we make websites, sometimes, we just don't want a code to be there... for
now. What I'm saying is, for example: Your name is Bob. Yes it's Bob. Bob made a website
and added lots of content. He gets a lot of traffic. He signs up for Google Adsense! Yay! He
is happy. He makes thousands of dollars a month. He is famous. And that is the exact reason why
your enemy, Angela, is trying to make your google adsense account bad. Guess what? Angela is your
sister. Yes she is your sister. What does that mean? She uses the same IP address....
I Need Help With Wordpress/php
I am lost with these files! (7) Okay, here is the story. I set up wordpress on my site. I know nothing about PHP and need help. I
need to know where the url and title info is stored. I checked in the header PHP file, and all I
saw was: CODE <title><?php bloginfo('name'); wp_title();
?></title> And <div id="header"> <h1><a
href="<?php bloginfo('url'); ?>"><?php
bloginfo('name'); ?></a></h1> </div> <!--
/header --> Whe....
Help With Removing Files And Folders
removing all files from a directory (4) Is there a function or a group of functions which I can use to delete all the files an folders in a
directory? I've tried rmdir() but it complains that it can't remove it because there are
files/folders in it. ....
Garbage Text
when i added php includes to a page (2) When i added php included to a page, it produced this really really weird garbage text befor and
after the table i have on the page. I was wondering if this has ever happened to anyone else. Not
sure what's producing the gargabe, i mean it's only a couple of characters, and i've
gone through everything and can't find anything. The other thing is that i can, and have gotten
rid of it by getting rid of the text befor the php include code which isn't a solution becasue i
want to keep the meta's and title on the page. this is what the garbage looks li....
Help With Reading Files
Read and replace/insert data from form (5) Hi, Does anyone know how i can do this, or scripts that will work on Trap17's servers and will
do the following: I have a .doc file form. Which i want to have filled in automactically, by HTML
Form and emailed to my address, with the data filled in. Any ideas? I have heard many differing
things, like XML, RTF, DOC, PDF... I have serched through many places and come up empty handed with
anything that works. /sad.gif' border='0' style='vertical-align:middle' alt='sad.gif' /> ....
Php/mysql Search Engine Help
Having issues displaying results (1) I've been using a tutorial
(http://www.devarticles.com/c/a/MySQL/Developing-A-Site-Search-Engine-With-PHP-And-MySQL/) at this
address to help me get started on building my own search engine. I've completed the tutorial but
when I run the search, I get no results on the results page. I'm wondering if anyone will take a
look at this script and see if they can figure out why my I'm not getting any results displayed.
I'm using phpMyAdmin to build the database and simple notepad to build the PHP script. CODE
<?php $submit = $_POST[&....
Help With Uploading Files!
(4) Here is the code i am going to use, written originaly for only 2 files, image and location, I added
'thumbnail', can someone check through it please? CODE $submit =
$_POST['submit']; $name = $_POST['name'];
$description = $_POST['description']; $age =
$_POST['age']; $subcat = $_POST['subcat']; $with
= $_POST['with']; $added = $_POST['added'];
$type = $_POST['type....
Change Permission With Php Code
code to change files' and folders' permissions? (3) As everyone know, there two ways (that I can think of) to change files' and directories'
permissions. One is to change it in your cPanel's Disk Manager and the other is with an FTP
client that supports chmod. Well, I'm doing something for my site that requires files to have
full permissions (Execute, Write, and Read on all three groups). At first, I thought that if I made
the directory 777, then every file created in that directory will be 777 as well. I'm wrong. An
alternative to doing this is to change each file permission myself, but that would be....
Blog Using Php: Files Or Mysql?
(9) I've been planning to put up a blog on my site but I'm having trouble with how I should do
it. I don't really know how blogs are made. Is it a database or a flat file? I know how to
write to a file using PHP but I still don't know how to put the last entry on the top of the
file. That's a big issue in the shoutbox I made for my site. If you look at it, the shouts
keep appending at the end of the file and I want it to be on top. Can anyone help me please? It
would be nice if you'd give me detailed instructions on how to put it up, with files....
Getting List Of Directories And Files Using Php
PHP Function for Directory and File List (6) is there a php function that lists the content of some folder.... example: /New folder new.txt
left.gif download.zip dc.exe ....so is there..? /rolleyes.gif' border='0'
style='vertical-align:middle' alt='rolleyes.gif' /> ....
Looking for displaying, latest, added, files, subdirectories
|
|
Searching Video's for displaying, latest, added, files, subdirectories
|
advertisement
|
|