[Question] How use the crawldir function?

Discuss the development of future releases of phpBB (phpBB 3.x minor releases) and MODing/Coding related questions.
Post Reply
Dakin Quelia
New member
New member
Posts: 49
Joined: 12 Nov 2008, 01:26
Real name: Daniel
Location: Belgique

[Question] How use the crawldir function?

Post by Dakin Quelia »

Hi,

I created a download page and for it I began in using this [url=http://fail.infinityhouse.org/pastebin.php?mode=view&s=5]function[/url]. But I don't understand his functionning.

A little help is welcome. Thanks per advance. ;)

See you soon,
Last edited by Dakin Quelia on 02 Nov 2009, 22:07, edited 1 time in total.
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: [Question] How use the crawldir function?

Post by Obsidian »

To start, I'd recommend you read this topic a little bit. You'll see some things in there pertaining to crawldir.
http://phpbbmodders.net/board/viewtopic.php?f=55&t=2977&start=15

Also, that copy of crawldir in my pastebin is a bit old, there's another copy here that is updated and fixes an issue or two.
http://code.assembla.com/phpbb-xerxes/subversion/nodes/trunk/root/includes/crs/extension/extension_crawldir.php#ln43

Also, if you want to see an example of how crawldir is used within a working MOD, I'd recommend you tear [url=http://phpbbmodders.net/board/viewtopic.php?f=37&t=3128]this MOD[/url] apart.
Dakin Quelia
New member
New member
Posts: 49
Joined: 12 Nov 2008, 01:26
Real name: Daniel
Location: Belgique

Re: [Question] How use the crawldir function?

Post by Dakin Quelia »

I go to read this topic.

For the mod, I saw but my main goal is make a simple downloa page. ;)

Thank you. ;)
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: [Question] How use the crawldir function?

Post by Obsidian »

What is it that you don't understand, specifically?
Dakin Quelia
New member
New member
Posts: 49
Joined: 12 Nov 2008, 01:26
Real name: Daniel
Location: Belgique

Re: [Question] How use the crawldir function?

Post by Dakin Quelia »

I took this [url=http://phpbbmodders.net/board/viewtopic.php?p=18076#p18076]code[/url].

I have some difficulties with that. I tested in download page, the function: crawldir('downloads'); but it doesn't work. :(

I'd also like to add a specific icon by extension and sort by dir before files. ;)

My old code is (before changes):

Code: Select all

$dirname    = 'downloads';
$files         = scandir($dirname);

foreach&
nbsp;($files as $file) 
{
&
nbsp;   if ($file != '.' && $file != '..') 
&
nbsp;   {
&
nbsp;       // Traitement si c'est un dossier
        if (is_dir($dirname . '/' . $file)) 
&
nbsp;       {
&
nbsp;           $image         = './theme/images/dir.gif';
&
nbsp;           $filename     = $file;
&
nbsp;           $download    = $dirname . '/' . $file;
&
nbsp;       } 
&
nbsp;       else
&
nbsp;       {
&
nbsp;           $ext = strtolower(array_pop(explode('.', $file)));

&
nbsp;           // Traitement pour les fichiers TXT
            if ($ext == 'txt')
&
nbsp;           {
&
nbsp;               $image         = './theme/images/txt.gif';
&
nbsp;               $filename     = $file;
&
nbsp;               $filedate    = date("d/m/Y h:m:s", filemtime($dirname . '/' . $file));
&
nbsp;               $filesize    = filesize($dirname . '/' . $file);
&
nbsp;               $download    = $dirname . '/' . $file;
&
nbsp;           }
&
nbsp;           // Traitement pour les fichiers PDF
            elseif ($ext == 'pdf')
&
nbsp;           {
&
nbsp;               $image = './theme/images/pdf.gif';
&
nbsp;               $filename     = $file;
&
nbsp;               $filedate    = date("F d Y H:i:s.", filemtime($dirname . '/' . $file));
&
nbsp;               $filesize    = filesize($dirname . '/' . $file);
&
nbsp;               $download    = $dirname . '/' . $file;
&
nbsp;           }
&
nbsp;           // Traitement pour les fichiers ZIP
            elseif ($ext == 'zip')
&
nbsp;           {
&
nbsp;               $image         = './theme/images/zip.gif';
&
nbsp;               $filename     = $file;
&
nbsp;               $filedate    = date("d/m/Y h:m:s", filemtime($dirname . '/' . $file));
&
nbsp;               $filesize    = filesize($dirname . '/' . $file);
&
nbsp;               $download    = $dirname . '/' . $file;
&
nbsp;           }
&
nbsp;           // Traitement pour les fichiers PHP
            elseif ($ext == 'php')
&
nbsp;           {
&
nbsp;               $image         = './theme/images/php.png';
&
nbsp;               $filename     = $file;
&
nbsp;               $filedate    = date("d/m/Y h:m:s", filemtime($dirname . '/' . $file));
&
nbsp;               $filesize    = filesize($dirname . '/' . $file);
&
nbsp;               $download    = $dirname . '/' . $file;
&
nbsp;           }
&
nbsp;           // Traitement pour les fichiers EXCEL
            elseif ($ext == 'xls')
&
nbsp;           {
&
nbsp;               $image         = './theme/images/excel.png';
&
nbsp;               $filename     = $file;
&
nbsp;               $filedate    = date("d/m/Y h:m:s", filemtime($dirname . '/' . $file));
&
nbsp;               $filesize    = filesize($dirname . '/' . $file);
&
nbsp;               $download    = $dirname . '/' . $file;
&
nbsp;           }
&
nbsp;           // Traitement pour les fichiers POWER POINT
            elseif ($ext == 'ppt')
&
nbsp;           {
&
nbsp;               $image         = './theme/images/powerpoint.png';
&
nbsp;               $filename     = $file;
&
nbsp;               $filedate    = date("d/m/Y h:m:s", filemtime($dirname . '/' . $file));
&
nbsp;               $filesize    = filesize($dirname . '/' . $file);
&
nbsp;               $download    = $dirname . '/' . $file;
&
nbsp;           }
&
nbsp;       }
&
nbsp;   }
&
nbsp;   else
&
nbsp;   {
&
nbsp;       $image         = './theme/images/dir.gif';
&
nbsp;   }
&
nbsp;   
&
nbsp;   // Bloque
    $template->assign_block_vars('file', array(
&
nbsp;       'DESCRIPTION'    => $description,
&
nbsp;       'FILENAME'        => $filename,
&
nbsp;       'FILEDATE'        => $filedate,
&
nbsp;       'FILESIZE'        => $filesize,
&
nbsp;       'DOWNLOAD'        => $download,
&
nbsp;       'FILESIZE'         => $filesize,
&
nbsp;       'IMAGE'            => $image,
&
nbsp;   ));
}&
nbsp;   Â


But I prefer a code phpBB. ;)
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: [Question] How use the crawldir function?

Post by Obsidian »

Okay, can you turn on DEBUG and DEBUG_EXTRA for me please, when you test?

Also, try using this for the crawldir call:

Code: Select all

$results = crawldir('./downloads'); Â


Sorting by dir before files is actually impossible. Files and directories are returned separately, because crawldir is a full scan of a directory and its contents (and contents of subdirectories, and the contents of the directories in the subdirectories, etc.)
It's hard to explain, it makes more sense when you're looking at some example results.
With that function call above, put these line after it. I'd like to see the page output if you'd be so kind. :)

Code: Select all

echo&nbsp;'<pre>';
var_dump($results);
exit_handler('</pre');&nbsp;Â
Dakin Quelia
New member
New member
Posts: 49
Joined: 12 Nov 2008, 01:26
Real name: Daniel
Location: Belgique

Re: [Question] How use the crawldir function?

Post by Dakin Quelia »

Obsidian wrote:Okay, can you turn on DEBUG and DEBUG_EXTRA for me please, when you test?

Also, try using this for the crawldir call:

Code: Select all

$results&nbsp;=&nbsp;crawldir('./downloads');&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Â

With that function call above, put these line after it.

Code: Select all

echo&nbsp;'<pre>';
var_dump($results);
exit_handler('</pre');&nbsp;&nbsp;&nbsp;Â


I tested and I get that. ;)

Code: Select all

array(3) {
  ["dirs"]=>
  array(2) {
    [0]=>
    string(11) "./downloads"
    [1]=>
    string(16) "./downloads/test"
  }
  ["files"]=>
  array(1) {
    [0]=>
    array(2) {
      [0]=>
      string(34) "./downloads/phpbb-astuces-mods.txt"
      [1]=>
      string(21) "./downloads/video.php"
    }
  }
  ["subdirs"]=>
  array(1) {
    [0]=>
    array(1) {
      [0]=>
      string(16) "./downloads/test"
    }
  }
}


Obsidian wrote:With that function call above, put these line after it. I'd like to see the page output if you'd be so kind.


Is it the php page or the template page?
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: [Question] How use the crawldir function?

Post by Obsidian »

PHP page. This will output what crawldir returns..

Also, that is the old crawldir you are using, I can tell by the results. There was a bug that was fixed with the 1.4.0 release of crawldir, for relative results.

I recommend updating the copy of crawldir that you have to the one that I linked earlier, to avoid the bug from cropping up in your site.
Dakin Quelia
New member
New member
Posts: 49
Joined: 12 Nov 2008, 01:26
Real name: Daniel
Location: Belgique

Re: [Question] How use the crawldir function?

Post by Dakin Quelia »

Here are my [url=http://www.megaupload.com/?d=670J5J28]download page[/url]. ;)

I replaced the previous function by the function upddated. :)

I get this error:

Code: Select all

Fatal error: Default value for parameters with array type hint can only be an array or NULL in C:\Users\Daniel Chals�che\Documents\phpBBPortable\App\phpbb\includes\functions_global.php on line 62
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: [Question] How use the crawldir function?

Post by Obsidian »

Ah, crap.

For the crawldir call, use this:

Code: Select all

$results = crawldir('./downloads', NULL, NULL);
Dakin Quelia
New member
New member
Posts: 49
Joined: 12 Nov 2008, 01:26
Real name: Daniel
Location: Belgique

Re: [Question] How use the crawldir function?

Post by Dakin Quelia »

I tested but it doesn't work. It displays the same message. :(
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: [Question] How use the crawldir function?

Post by Obsidian »

Odd.

Try this for the downloads file.

Code: Select all

<?php
/**
 *
 * @author Daniel Chalsèche (Dakin Quelia) http://www.danielchalseche.be/
 * @author Mickael Carlavan (Mika)
 * @autho Ani'
 *
 * @package Downloads
 * @version $Id: post.php 2009-08-12 02:31:25 Dakin Quelia $
 * @copyright (c) 2009 Daniel Chalsèche
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
 */

/**
* @ignore
*/
define('IN_SITE', true);
define('SITE_ROOT', './');
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
include(SITE_ROOT . 'common.' . PHP_EXT);
include(SITE_ROOT . 'includes/functions_global.' . PHP_EXT);
include(PHPBB_ROOT_PATH . 'includes/functions_display.' . PHP_EXT);

// Lance les sessions
$user->session_begin();
$auth->acl($user->data);
$user->setup('downloads');
 
/*$dirname    = 'downloads';
$files       = scandir($dirname);

foreach ($files as $file)
{
   if ($file != '.' && $file != '..')
   {
      // Traitement si c'est un dossier
      if (is_dir($dirname . '/' . $file))
      {
         $image       = './theme/images/dir.gif';
         $filename    = $file;
         $download   = $dirname . '/' . $file;
      }
      else
      {
         $ext = strtolower(array_pop(explode('.', $file)));

         // Traitement pour les fichiers TXT
         if ($ext == 'txt')
         {
            $image       = './theme/images/txt.gif';
            $filename    = $file;
            $filedate   = date("d/m/Y h:m:s", filemtime($dirname . '/' . $file));
            $filesize   = filesize($dirname . '/' . $file);
            $download   = $dirname . '/' . $file;
         }
         // Traitement pour les fichiers PDF
         elseif ($ext == 'pdf')
         {
            $image = './theme/images/pdf.gif';
            $filename    = $file;
            $filedate   = date("F d Y H:i:s.", filemtime($dirname . '/' . $file));
            $filesize   = filesize($dirname . '/' . $file);
            $download   = $dirname . '/' . $file;
         }
         // Traitement pour les fichiers ZIP
         elseif ($ext == 'zip')
         {
            $image       = './theme/images/zip.gif';
            $filename    = $file;
            $filedate   = date("d/m/Y h:m:s", filemtime($dirname . '/' . $file));
            $filesize   = filesize($dirname . '/' . $file);
            $download   = $dirname . '/' . $file;
         }
         // Traitement pour les fichiers PHP
         elseif ($ext == 'php')
         {
            $image       = './theme/images/php.png';
            $filename    = $file;
            $filedate   = date("d/m/Y h:m:s", filemtime($dirname . '/' . $file));
            $filesize   = filesize($dirname . '/' . $file);
            $download   = $dirname . '/' . $file;
         }
         // Traitement pour les fichiers EXCEL
         elseif ($ext == 'xls')
         {
            $image       = './theme/images/excel.png';
            $filename    = $file;
            $filedate   = date("d/m/Y h:m:s", filemtime($dirname . '/' . $file));
            $filesize   = filesize($dirname . '/' . $file);
            $download   = $dirname . '/' . $file;
         }
         // Traitement pour les fichiers POWER POINT
         elseif ($ext == 'ppt')
         {
            $image       = './theme/images/powerpoint.png';
            $filename    = $file;
            $filedate   = date("d/m/Y h:m:s", filemtime($dirname . '/' . $file));
            $filesize   = filesize($dirname . '/' . $file);
            $download   = $dirname . '/' . $file;
         }
      }
   }
   else
   {
      $image       = './theme/images/dir.gif';
   }
   
   // Bloque
   $template->assign_block_vars('file', array(
      'DESCRIPTION'   => $description,
      'FILENAME'      => $filename,
      'FILEDATE'      => $filedate,
      'FILESIZE'      => $filesize,
      'DOWNLOAD'      => $download,
      'FILESIZE'       => $filesize,
      'IMAGE'         => $image,
   ));
}*/
   
$results = crawldir(SITE_ROOT . 'downloads', NULL, NULL);
echo '<pre>';
var_dump($results);
exit_handler('</pre');
die();

// Here we will actually process the crawldir results, but meh.   Need to get this working first.

// Titre de la page
$site->page_header($user->lang['DOWNLOAD_PAGE']);

$template->assign_vars(array(
   'TEST'   => 'test',
));

$template->set_filenames(array(
   'body'   => 'download_body.html',
));

$site->page_footer();

?>
Dakin Quelia
New member
New member
Posts: 49
Joined: 12 Nov 2008, 01:26
Real name: Daniel
Location: Belgique

Re: [Question] How use the crawldir function?

Post by Dakin Quelia »

I'm sorry to disturb you but it doesn't always work. :(
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: [Question] How use the crawldir function?

Post by Obsidian »

No problem. Uhm, there's a copy of a working crawldir over here, http://code.assembla.com/phpbb-xerxes/s ... .php#ln164
1.4.2 was problematic as I was attempting it to be PHP5 compatible only, iirc. This one, 1.4.1, has been field tested and should work.
Post Reply