TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-09-2008, 08:15 PM   #1 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Application RESOLVED -- List only some extention (File Listing)

Good day to you all,
I'm working on a pice of code which list all files in a directory and return the list and its content right under the name of the file.

PHP Code:

<?php
$thelist 
"";
 if (
$handle opendir('.')) {
   while (
false !== ($file readdir($handle)))
      {
          if (
$file != "." && $file != "..")
      {
              
$thelist .= '<a href="'.$file.'">'.$file.'</a><br/>';
            
$contents file($file);
            
$string implode($contents);
            
$thelist .= '<p>'.$string.'</p>';
            
          }
       }
  
closedir($handle);
  }
?>
<P>List of files:</p>
<P><?=$thelist?></p>
I'm looking for a way of choose only 3 or 4 extension only.

How would I dow so ?

Thanks !
__________________
That's why we are not alone on earth... let's build !

Last edited by Peuplarchie : 11-10-2008 at 01:08 AM.
Peuplarchie is offline  
Reply With Quote
Old 11-09-2008, 11:21 PM   #2 (permalink)
The Contributor
 
Runar's Avatar
 
Join Date: Nov 2008
Location: Norway
Posts: 58
Thanks: 20
Runar is on a distinguished road
Default

I quite recently learned that glob() is the way to do this. The function will find pathnames matching a pattern (according to the manual) and works perfectly as a replacement for opendir() and all those functions.

PHP Code:
<?php

// Turn on error reporting
ini_set'display_errors''yes' );

// Set path to our directory (for easier use)
// Remember the last slash (/)!
$directory_path 'your/folder/';

// Return .png files found in the directory
foreach( glob$directory_path '{ *.file1, *.file2, *.file3 }'GLOB_BRACE ) as $file )
{
    
// Put some file data in variables
    
$name basename$file );
    
$size filesize$file );
    
$file implodefile$file ) );
    
    
// Do your thing, for example add the info to an array
    // or output it directly
    // $files[]  = array( 'name' => $name, 'size' => $size, 'content' => $file );
}
    
?>
Send a message via MSN to Runar
Runar is offline  
Reply With Quote
Old 11-10-2008, 10:44 AM   #3 (permalink)
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default

Runar you beat me to it :)

And one more thing. I think one should make a habit of using:

PHP Code:
<?PHP $variable ?>
Instead of:

PHP Code:
<?=$variable?>
Thats my opinion anyway.

Cheers.
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.
EyeDentify is offline  
Reply With Quote
Old 11-10-2008, 01:14 PM   #4 (permalink)
The Contributor
 
Runar's Avatar
 
Join Date: Nov 2008
Location: Norway
Posts: 58
Thanks: 20
Runar is on a distinguished road
Default

You're right, but I guess he would have to use echo() if he would like to print the variable:
PHP Code:
<?php echo $variable ?>

Last edited by Runar : 11-11-2008 at 02:45 AM.
Send a message via MSN to Runar
Runar is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:34 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design