. and .. appear instead of pics


#1

First of all, thanks very much for providing this forum. It is very much appreciated!

My son-in-law created a php script for my website about 10 years ago to show pictures like a manual slideshow, and it worked fine for many years. I just recently discovered that it now has a problem and I wonder if it has to do with this host having different parameters.

The problem is as follows:

The first pic shows a . , the second shows … , and the third shows the first pic, the fourth shows the second pic, etc.

I need to get rid of pics 1 and 2 which are displaying as . and …

My son-in-law told me to add a # before @files in the

#remove the … and . directories

and it should remove the dots but it does not. He can’t think of any other suggestions. The full code is as follows:

#!/usr/bin/perl

#this script will act as a type of slide show

use CGI;

if(CGI::param(‘directory’) eq undef) {
print CGI::header();

open(F, “pictures.txt”);
chop(@directories = );
close(F);
foreach (@directories) {
my($pDirectory, $title) = split(/::/);
my($hrefTitle) = $title;
$pDirectory = $pDirectory;

#remove the spaces
$pDirectory =~ s/ / /g;
$hrefTitle =~ s/ / /g;

print " <A HREF="/cgi-bin/pics.pl?directory=$pDirectory&title=$hrefTitle">$title
";
}
} else {
#variables
my($serverRoot) = “/home/ma3ry/christiangays.com”;
my($directory) = “/” . CGI::param(‘directory’);
my($i) = 0;
my($max) = 0;
my(@files) = ();

$i = CGI::param(‘picNum’) unless(CGI::param(‘picNum’) == undef);

#open the directory
if(opendir(DIR, “$serverRoot/$directory”)) {

#read in the contents of the directory
my(@files) = readdir(DIR);

#remove the … and . directories
#@files = splice(@files, 2);

#sort the files
@files = sort(@files);

#find out how many pics there are
my($max) = @files *1;

#build the page
&createPage($directory, $files[$i], $i, $max, CGI::param(‘directory’), CGI::param(‘title’));

#close the directory
closedir(DIR);

} else {
#directory is not found
print “Content-type: text/html\n\n”;
print “Couldn’t open directory $directory!\n\n”;
}
}

exit(0);

sub createPage {
my($directory) = shift;
my($picName) = shift;
my($i) = shift;
my($max) = shift;
my($hrefDirectory) = shift;
my($title) = shift;
my($j) = $i - 1;
$i++;

print “Content-type: text/html\n\n”;
print (<<HTML);




HTML

#replace the spaces
$title =~ s/ / /g;

if($j >= 0) {
print “<a href=”/cgi-bin/pics.pl?directory=$hrefDirectory&title=$title&picNum=$j">Previous

\n";
} else {
print “previous

\n”;
}

if($i - 10 > 0) {
print “<a href=”/cgi-bin/pics.pl?directory=$hrefDirectory&title=$title&picNum=", $i - 11, “”>Jump back
10 pictures

\n";
} else {
print “Jump back
10 pictures

\n”;
}

if($i - 1 != 0) {
print “<a href=”/cgi-bin/pics.pl?directory=$hrefDirectory&title=$title&picNum=0">Start\n";
} else {
print “start\n”;
}

#put the spaces back in
$title =~ s/ / /g;

print(<<HTML);






Return to pictures list

$title

You are viewing picture $i of $max

$picName






HTML

#drop the extra one off the end
$max–;

#take out the spaces
$title =~ s/ / /g;

if($i <= $max) {
print “<a href=”/cgi-bin/pics.pl?directory=$hrefDirectory&title=$title&picNum=$i">Next

\n";
} else {
print “next

\n”;
}

if($i <= $max - 10) {
print “<a href=”/cgi-bin/pics.pl?directory=$hrefDirectory&title=$title&picNum=", $i + 9, “”>Jump ahead
10 pictures

\n";
} else {
print “Jump ahead
10 pictures

\n”;
}

if($i <= $max) {
print “<a href=”/cgi-bin/pics.pl?directory=$hrefDirectory&title=$title&picNum=", $max, “”>End\n";
} else {
print “end\n”;
}

print (<<HTML);






Return to ChristianGays.com

HTML

}


#2

Did you change the line

#@files = splice(@files, 2);

from

@files = splice(@files, 2);

It should remove the first to entries, without the #, and those two should be “.” and “…”.


#3

Ah, yes, I know why.

You are now on a server, where “.” and “…” are not the first two. We have to remove them in another way - just wait a moment, and I’ll give you the code. I have to test it first.


#4

After the lines:

add these

my($k);
for ($k=$#files;$k>=0;$k–) {
if ($files[$k] eq “.” or $files[$k] eq “…”) {
splice(@files,$k,1);
}
}


#5

Which should have been, that you add the code after these two lines:

#remove the … and . directories
#@files = splice(@files, 2);


#6

[code]@files = grep { $_ ne ‘.’ and $_ ne ‘…’ } @files;

OR instead combine statements

my(@files) = sort grep { $_ ne ‘.’ and $_ ne ‘…’ } readdir(DIR);[/code]
PS. Also it is a Perl script, not a PHP script.

Customer since 2000 :cool: openvein.org


#7

Hallelujah! You’re a Godsend!!! Thank you so very, very, very much!!! It works!!!

God bless,
Mary