Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What am I missing?

Status
Not open for further replies.

mtorbin

Technical User
Nov 5, 2002
369
US
Hey all,

Ok, here is the CGI file:

#!/usr/bin/perl

opendir (FTPDIR, "../effTeePee/");
print 'YES I GOT THIS FAR!';


## my @folderContents = readdir (FTPDIR);
## closedir (FTPDIR);

## print "Content-type: text/html\n\n";

## if (@folderContents) {
## print 'This directory contains<br><br>';

## foreach (sort @folderContents) {
## print "$_";
## }
## }

As you can see, parts of it are commented out. The reason for this is that I keep getting this error on line 3. I checked the permissions on the directory and they're 755. So what gives? What am I missing?

- MT
 
our script produced this error: Cannot open directory at listFiles.cgi line 3.

Now, I'm thinking that the error might be the permissions on the directory which FOR SOME UNKNOWN REASON, Tripod is standing in my way of changing.

Is there a free host out there that will give me a few MB for testing that won't stand in my way of directory permissions??

- MT
 
Hi

Interesting. I get Internal Server Error. But if I put a "[tt]Content-type: text/html\n\n[/tt]" before that uppercase message, then works fine.

I put your script in my cgi-bin directory and created an effTeePee directory. That's all. I have this files :
[tt]
~/cgi-bin/mtorbin.pl
~/effTeePee/somefile.txt
[/tt]

By the way, Tripod does a good work with settings, so you never have to check permissions.

Feherke.
 
Feherke,

So what do you suggest?

- MT
 
Hi

I remembered finally. The script will never work this way on Tripod. They run the [tt]CGI[/tt] scripts on a different server. So you have to use a structure like this :
[tt]
~/cgi-bin/mtorbin.pl
~/cgi-bin/effTeePee/somefile.txt
[/tt]

And modify the path in [tt]opendir()[/tt] function.

Feherke.
 
if you run this script as a browser based script (CGI) it will not work:

#!/usr/bin/perl

opendir (FTPDIR, "../effTeePee/");
print 'YES I GOT THIS FAR!';

you have to print an http header first before attempting to print anything to the browser, which is why this enables the script to run:

But if I put a "Content-type: text/html\n\n" before that uppercase message, then works fine.
 
Here's what I've got so far:

#!/usr/bin/perl

print "Content-type: text/html\n\n";

opendir (FTPDIR, "~/effTeePee/") || die("Cannot open directory"); # line 5
print 'YES I GOT THIS FAR!';

And here's the response I get:

Status: 302 Found Location: /bin/error?error=Your script produced this error%3A %3Cbr%3ECannot open directory at listFiles.cgi line 5. URI: /bin/error?error=Your script produced this error%3A %3Cbr%3ECannot open directory at listFiles.cgi line 5. Content-type: text/html

Am I still missing something? This should be obvious, right?
 
try this:-

Code:
[b]#!/usr/bin/perl[/b]

print "Content-type: text/html\n\n";

print `ls ~`;


Kind Regards
Duncan
 
the "~" in the directory path is suspect to me. Try ".." like you had before. You may also need to use the full path to the folder instead of trying relative paths like "../folder".

It should be obvious: there are other free servers better than tripod. [thumbsup]
 
Hi Feherke,

I read your posts, and the last one has this:

~/cgi-bin/mtorbin.pl
~/cgi-bin/effTeePee/somefile.txt

so I think you maybe confused mtorbin with the "~" in the path.
 
Sorry I haven't posted progress until now:

#!/usr/bin/perl -wT

print "Content-type: text/html\n\n";

opendir (FTPDIR, "/var/ || Error ('open', 'directory');

my @folderContents = readdir (FTPDIR);
closedir (FTPDIR);

if (@folderContents) {
foreach my $indivFile (@folderContents) {
my $fullUnit = $indivFile;
my (@nameParts, $name, $extension, $graphic);
@nameParts = split (/./ , $indivFile);
($name, $extension) = split (/,/);
print "<tr valign=top>\n";
print "<td align=center><img src=images/icon_" . $extension . ".gif width=18 height=22></td>\n";
print "<td>$fullUnit</td>\n";
print "<td>[DATE]</td>\n";
print "<td>[SIZE]</td>\n";
print "</tr>";
}
}

I think this could probably use some clean up, right?

- MT
 
Here's the FULL code (may NOT be correct):

#!/usr/bin/perl -wT

print "Content-type: text/html\n\n";

opendir (FTPDIR, "/var/ || Error ('open', 'directory');

my @folderContents = readdir (FTPDIR);
closedir (FTPDIR);

print "<html>\n";
print "<head>\n";
print "<title>Untitled Document</title>\n";
print "<link href=ftpStyle.css rel=stylesheet type=text/css>\n";
print "<script src=jsLib.js></script>\n";
print "</head>\n";
print "<body>\n";
print "<table width=80% border=0 align=center cellpadding=0 cellspacing=0>\n";
print "<tr align=center valign=top>\n";
print "<td width=19 height=20><img src=images/box_gray_corner_tl.gif width=19 height=20></td>\n";
print "<td background=images/box_gray_side_t.gif><img src=images/box_gray_side_t.gif width=2 height=20></td>\n";
print "<td width=19 height=20><img src=images/box_gray_corner_tr.gif width=19 height=20></td>\n";
print "</tr>\n";
print "<tr align=center valign=top>\n";
print "<td background=images/box_gray_side_l.gif><img src=images/box_gray_side_l.gif width=19 height=2></td>\n";
print "<td bgcolor=#f2f2f2>\n";
print "<table width=100% border=0 cellspacing=5 cellpadding=0>\n";
print "<tr valign=top>\n";
print "<td width=3% align=center>&nbsp;</td>\n";
print "<td width=80% class=tableHeader>Name</td>\n";
print "<td width=7% class=tableHeader>Date</td>\n";
print "<td width=10% class=tableHeader>Size</td>\n";
print "</tr>\n";
print "<tr valign=top>\n";
print "<td align=center><img src=images/icon_folderOpen.gif width=27 height=22></td>\n";
print "<td>/ Folder Name </td>\n";
print "<td>&nbsp;</td>\n";
print "<td>&nbsp;</td>\n";
print "</tr>\n";

if (@folderContents) {
foreach my $indivFile (@folderContents) {
my $fullUnit = $indivFile;
my @nameParts = split (/./ , $indivFile);

foreach (@nameParts) {
my ($name, $extension);
($name, $extension) = split (/,/);
print "<tr valign=top>\n";
print "<td align=center><img src=images/icon_" . $extension . ".gif width=18 height=22></td>\n";
print "<td>$fullUnit</td>\n";
print "<td>[DATE]</td>\n";
print "<td>[SIZE]</td>\n";
print "</tr>";
}
}
}

print "</table>\n";
print "<br>\n";
print "<br>\n";
print "</td>\n";
print "<td background=images/box_gray_side_r.gif><img src=images/box_gray_side_r.gif width=19 height=2></td>\n";
print "</tr>\n";
print "<tr align=center valign=top>\n";
print "<td width=19 height=20><img src=images/box_gray_corner_bl.gif width=19 height=20></td>\n";
print "<td background=images/box_gray_side_b.gif><img src=images/box_gray_side_b.gif width=2 height=20></td>\n";
print "<td width=19 height=20><img src=images/box_gray_corner_br.gif width=19 height=20></td>\n";
print "</tr>\n";
print "</table>\n";
print "</body>\n";
print "</html>\n";
 
New Changes, still has problems:

#!/usr/bin/perl -wT

print "Content-type: text/html\n\n";

opendir (FTPDIR, "/var/ || Error ('open', 'directory');

my @folderContents = readdir (FTPDIR);
closedir (FTPDIR);

print "<html>\n";
print "<head>\n";
print "<title>Untitled Document</title>\n";
print "<link href=../ftpStyle.css rel=stylesheet type=text/css>\n";
print "<script src=../jsLib.js></script>\n";
print "</head>\n";
print "<body>\n";
print "<table width=80% border=0 align=center cellpadding=0 cellspacing=0>\n";
print "<tr align=center valign=top>\n";
print "<td width=19 height=20><img src=../images/box_gray_corner_tl.gif width=19 height=20></td>\n";
print "<td background=../images/box_gray_side_t.gif><img src=../images/box_gray_side_t.gif width=2 height=20></td>\n";
print "<td width=19 height=20><img src=../images/box_gray_corner_tr.gif width=19 height=20></td>\n";
print "</tr>\n";
print "<tr align=center valign=top>\n";
print "<td background=../images/box_gray_side_l.gif><img src=../images/box_gray_side_l.gif width=19 height=2></td>\n";
print "<td bgcolor=#f2f2f2>\n";
print "<table width=100% border=0 cellspacing=5 cellpadding=0>\n";
print "<tr valign=top>\n";
print "<td width=3% align=center>&nbsp;</td>\n";
print "<td width=80% class=tableHeader>Name</td>\n";
print "<td width=7% class=tableHeader>Date</td>\n";
print "<td width=10% class=tableHeader>Size</td>\n";
print "</tr>\n";
print "<tr valign=top>\n";
print "<td align=center><img src=../images/icon_folderOpen.gif width=27 height=22></td>\n";
print "<td>/ Folder Name </td>\n";
print "<td>&nbsp;</td>\n";
print "<td>&nbsp;</td>\n";
print "</tr>\n";

if (@folderContents) {
foreach my $indivFile (@folderContents) {
my $fullUnit = $indivFile;
my @nameParts = split (/./ , $indivFile);

foreach (@nameParts) {
my ($name, $extension);
($name, $extension) = split (/,/);
print "<tr valign=top>\n";
print "<td align=center><img src=../images/icon_" . $extension . ".gif width=18 height=22></td>\n";
print "<td>$fullUnit</td>\n";
print "<td>[DATE]</td>\n";
print "<td>[SIZE]</td>\n";
print "</tr>";
}
}
}

print "</table>\n";
print "<br>\n";
print "<br>\n";
print "</td>\n";
print "<td background=../images/box_gray_side_r.gif><img src=../images/box_gray_side_r.gif width=19 height=2></td>\n";
print "</tr>\n";
print "<tr align=center valign=top>\n";
print "<td width=19 height=20><img src=../images/box_gray_corner_bl.gif width=19 height=20></td>\n";
print "<td background=../images/box_gray_side_b.gif><img src=../images/box_gray_side_b.gif width=2 height=20></td>\n";
print "<td width=19 height=20><img src=../images/box_gray_corner_br.gif width=19 height=20></td>\n";
print "</tr>\n";
print "</table>\n";
print "</body>\n";
print "</html>\n";
 
It's this part:

if (@folderContents) {
foreach my $indivFile (@folderContents) {
my $fullUnit = $indivFile;
my @nameParts = split (/./ , $indivFile);

foreach (@nameParts) {
my ($name, $extension);
($name, $extension) = split (/,/);
print "<tr valign=top>\n";
print "<td align=center><img src=../images/icon_" . $extension . ".gif width=18 height=22></td>\n";
print "<td>$fullUnit</td>\n";
print "<td>[DATE]</td>\n";
print "<td>[SIZE]</td>\n";
print "</tr>";
}
}
}

that keeps failing!

- MT
 
I'm thinking the job is done with the first "split".

How about:
Code:
if (@folderContents) {
   foreach my $indivFile (@folderContents) {
       my $fullUnit = $indivFile;
       # escape the following "."
       my ($name, $extension) = split (/\./ , $indivFile);
           print "<tr valign=top>\n";
           print "<td align=center><img src=../images/icon_" . $extension . ".gif width=18 height=22></td>\n";
           print "<td>$fullUnit</td>\n";
           print "<td>$name</td>\n";
           print "<td>$extension</td>\n";
           print "</tr>";
   }
 }

Thanks,
 
First he splits on a period, then he splits on a comma so it looks like there has to be two seperate splits to get to the data. Sounds like poorly structured data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top