Current location: Hot Scripts Forums » Programming Languages » PHP » read file-kist in directory: print list


read file-kist in directory: print list

Reply
  #1 (permalink)  
Old 06-09-04, 11:40 AM
thomasjojo thomasjojo is offline
Newbie Coder
 
Join Date: Jun 2004
Location: Norway
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
read file-kist in directory: print list

Hi there.

I try to read the file list in the directory, and print the list out in the web-page, with links to the files.

do u Know how? thanks..

.thomas
Reply With Quote
  #2 (permalink)  
Old 06-09-04, 01:04 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
PHP Code:

function Downloads($dir '.') {


 
//open current dir for reading..
  
$handle = @opendir($dir);

 
//start the table where files are going to be listed..
  
echo '<table border="1" width="50%" style="border-collapse: collapse;" bordercolor="#000000" align="center">
            <tr>
                <td width="40%" align="center"><b>File Name</b></td>
                <td width="30%" align="center"><b>File Size</b></td>
                <td width="30%" align="center"><b>Last Modified</b></td>
            </tr>'
;

//now loop through files..
  
while (false !== ($file readdir($handle))) {
    
//exclude the dots..
     
if ($file !== '.' && $file !== '..') {
      
//get file stats
        
$info stat($file);
        
$stat1 round($info['size'] / 10242);
        
$stat2 date('j-n-Y H:i:s'$info['mtime']);
        echo 
'<tr>
                  <td width="40%">'
;

        echo 
"<a href=\"$file\">$file</a></td>\n\t";

        echo 
'   <td width="30%" align="center">'.$stat1.' KB</td>
                 <td width="30%" align="center">'
.$stat2.'</td>
              </tr>'
;
     }
  }
  echo 
'</table>';
//clear the cache..
  
clearstatcache();

call this function anywhere and it should work
something like that:
PHP Code:

//this should include the file where the upper function exists

include_once('download.php');

//and now list
Downloads(); 
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 06-10-04, 04:03 PM
thomasjojo thomasjojo is offline
Newbie Coder
 
Join Date: Jun 2004
Location: Norway
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
merci!! kap khun krap!!

Thank you! is the values that pick out JUST gifs, jpgs, doc, eps
hard to insert?
Reply With Quote
  #4 (permalink)  
Old 06-10-04, 05:43 PM
Rapid Dr3am Rapid Dr3am is offline
Community VIP
 
Join Date: Jan 2004
Location: Liverpool, England
Posts: 752
Thanks: 0
Thanked 0 Times in 0 Posts
__________________
Placeholder, place signature here.
Reply With Quote
  #5 (permalink)  
Old 06-12-04, 07:40 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
Originally Posted by thomasjojo
merci!! kap khun krap!!

Thank you! is the values that pick out JUST gifs, jpgs, doc, eps
hard to insert?
of course
PHP Code:

function Downloads($dir '.') {


//open current dir for reading..
  
$handle = @opendir($dir);

//start the table where files are going to be listed..
  
echo '<table border="1" width="50%" style="border-collapse: collapse;" bordercolor="#000000" align="center">
            <tr>
                <td width="40%" align="center"><b>File Name</b></td>
                <td width="30%" align="center"><b>File Size</b></td>
                <td width="30%" align="center"><b>Last Modified</b></td>
            </tr>'
;

//now loop through files..
  
while (false !== ($file readdir($handle))) {
    
//exclude the dots..
     
$ext substr($file, -3);
     if (
$file !== '.' && $file !== '..' and ($ext == 'gif' or $ext == 'jpg' or $ext == 'doc' or $ext == 'eps')) {
      
//get file stats
        
$info stat($file);
        
$stat1 round($info['size'] / 10242);
        
$stat2 date('j-n-Y H:i:s'$info['mtime']);
        echo 
'<tr>
                  <td width="40%">'
;

        echo 
"<a href=\"$file\">$file</a></td>\n\t";

        echo 
'   <td width="30%" align="center">'.$stat1.' KB</td>
                 <td width="30%" align="center">'
.$stat2.'</td>
              </tr>'
;
     }
  }
  echo 
'</table>';
//clear the cache..
  
clearstatcache();

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with my largest perl script. Grabbing data from a file. Sunnmann Perl 2 04-23-08 03:27 AM
formmail problem gscraper Perl 12 08-27-04 03:06 AM
Upload Script Problem!!! seanknighton Perl 0 03-21-04 09:54 PM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 04:28 PM


All times are GMT -5. The time now is 10:38 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.