Re: Get file list of the dir.

2002-10-28 Thread Ruslan U. Zakirov
RK But this doesn't seem to be the problem ... What's printed in the
RK browser? Is there anything in the error logs? Is the name of the
RK directory to be read input from the user (if so, are you running
RK under taint mode?), and are the permissions appropriate?
Here is my module's code...
use strict;
use Apache::Constants qw(:common);
use Apache::File ();
use IO::Dir;

sub handler {
   my $r = shift;
   return DECLINED unless $r-content_type() eq '' or $r-content_type() eq 
'text/html';

   my $file = $r-filename;
   my $tmp=substr($file,rindex($file,'/')+1,length($file)-$_-1,'');

   if (-e $r-finfo)
   {
  return DECLINED;
   }

   $r-content_type('text/plain');
   $r-send_http_header;

   my htmls;
   my $refdir;
   opendir($refdir, $file);
   unless ($refdir)
   {
 $r-log_error(Err in opendir($refdir,$file) : $!);
 return SERVER_ERROR;
   }
   my $filedir;
   while ($filedir = readdir($refdir))
   {
 next if (not $filedir =~/.html/);
 push(htmls, $filedir) if (-f $file$filedir);
   }
   closedir($refdir);

   foreach my $html(htmls)
   {
 $html=$file.$html;

 my $fh;
 unless ($fh = Apache::File-new($file))
 {
$r-log_error(Couldn't open $file for reading: $!);
return SERVER_ERROR;
 }
 while ($fh)
 {
$r-print($_);
 }
 $fh-close();
   }
   return OK;
}

1;
__END__

I've attached file with browser output.
ݦ.!x..¦
index.htmlґ·imagesÒß·fotoÒñ·´ 
style.cssÒ


Re: Get file list of the dir.

2002-10-28 Thread Ruslan U. Zakirov
Thank you for your help!
I'm terribly sorry for getting your time, It's my fault.
There was an error in my code.
I'm inattentive foolish man.
But I've known new methods of reading directory listening.
Best regards.
___
Sorry for my English.




Re: Get file list of the dir.

2002-10-27 Thread masilva3
you can use opendir, like this:

  opendir($refdir, /home/user) or
die Err in opendir($refdir,/home/user) : $!;
  my $filedir;
  while ($filedir = readdir($refdir))
  {
 next if ($filedir =~ /\.{1,2}/);
 push(@dirs, $filedir) if (-d /home/user/$filedir);
  }
  closedir($refdir);

  I don't know if this resolve your problem.

  bye


 -- Mensagem original ---

 De  : Ruslan U. Zakirov [EMAIL PROTECTED]
 Para: [EMAIL PROTECTED]
 Cc  :
 Data: Sun, 27 Oct 2002 20:30:23 +0300
 Assunto : Get file list of the dir.

 I'm writing handler which generate some html from files in requested
 dir if requested file does not exist.
 I have a problem with getting file list of the directory.
 I've tried to use IO::Dir, like this
my @htmls;
my $dh = new IO::Dir ($req_dir);
if (defined $dh)
{
  while (defined($_ = $dh-read))
  {
if(m/(\w*?\.html)/)
{
  unshift(@htmls,$_);
}
  }
}
 This code successfully create array, but at the same time apache pri
nts
 something to user. And I have an abbracadabra in browser.
 May be I've missed some better way of getting file names?







Re: Get file list of the dir.

2002-10-27 Thread masilva3
I'm sorry, change -d by -f, for get file names and not directory

bye

 -- Mensagem original ---

 De  : masilva3 [EMAIL PROTECTED]
 Para: cubic [EMAIL PROTECTED]
 Cc  : modperl [EMAIL PROTECTED]
 Data: Sun, 27 Oct 2002 15:59:53 -0300
 Assunto : Re: Get file list of the dir.

 you can use opendir, like this:

   opendir($refdir, /home/user) or
 die Err in opendir($refdir,/home/user) : $!;
   my $filedir;
   while ($filedir = readdir($refdir))
   {
  next if ($filedir =~ /\.{1,2}/);
  push(@dirs, $filedir) if (-d /home/user/$filedir);
   }
   closedir($refdir);

   I don't know if this resolve your problem.

   bye


  -- Mensagem original ---
 
  De  : Ruslan U. Zakirov [EMAIL PROTECTED]
  Para: [EMAIL PROTECTED]
  Cc  :
  Data: Sun, 27 Oct 2002 20:30:23 +0300
  Assunto : Get file list of the dir.
 
  I'm writing handler which generate some html from files in request
ed
  dir if requested file does not exist.
  I have a problem with getting file list of the directory.
  I've tried to use IO::Dir, like this
 my @htmls;
 my $dh = new IO::Dir ($req_dir);
 if (defined $dh)
 {
   while (defined($_ = $dh-read))
   {
 if(m/(\w*?\.html)/)
 {
   unshift(@htmls,$_);
 }
   }
 }
  This code successfully create array, but at the same time apache p
ri
 nts
  something to user. And I have an abbracadabra in browser.
  May be I've missed some better way of getting file names?
 
 
 







Re: Get file list of the dir.

2002-10-27 Thread Randy Kobes
On Sun, 27 Oct 2002, Ruslan U. Zakirov wrote:

 I'm writing handler which generate some html from files in requested
 dir if requested file does not exist.
 I have a problem with getting file list of the directory.
 I've tried to use IO::Dir, like this
my htmls;
my $dh = new IO::Dir ($req_dir);
if (defined $dh)
{
  while (defined($_ = $dh-read))
  {
if(m/(\w*?\.html)/)
{
  unshift(htmls,$_);
}
  }
}
 This code successfully create array, but at the same time apache prints
 something to user. And I have an abbracadabra in browser.
 May be I've missed some better way of getting file names?

As a latter message indicated, there's a number of ways of
getting a file listing - another possibility is

my $dir = '/usr/local/apache/htdocs';
opendir(DIR, $dir) or die Cannot opendir $dir: $!;
my htmls = grep { /\.html?$/ } readdir DIR;
closedir DIR;

But this doesn't seem to be the problem ... What's printed in the
browser? Is there anything in the error logs? Is the name of the
directory to be read input from the user (if so, are you running
under taint mode?), and are the permissions appropriate?

-- 
best regards,
randy kobes