I'm having this really odd problem.. I've written a script that works through telnet, but not through a browser. If I run the -c switch through telnet it comes up with 'syntax OK' - and if I run -w I don't get any problems.
But, If I call it through my browser, I get a 'page cannot be displayed' message. Not even an error 500. I've come back to this after nearly 3 months with a clear head, and still can't figure out why..
Basically, the script scans a directory of image files against a flat file database.. if they're in the directory and not in the database it means they're redundant, and should be automatically transferred to a directory called 'remove'. That simple.
It's listed below - I've commented where it stops working in browsers.
Thanks for any help!
Matt.
#!/usr/local/bin/perl
#set content type
print "Content-type:text/html\n\n";
#HTML header
print "<html><head><title>w</title></head><body>Images to remove\n";
#check which products file to use
open (WHO,"data/whichfile.txt"
;
$whichfile = <WHO>;
close (WHO);
print "$whichfile is current file<br><br>\n";
#open current products file - store in @products
open (INFILE,"data/$whichfile"
or dienice("Can't open products file: $!"
;
@products = <INFILE>;
close (INFILE);
#open images directory - store in @allimages
opendir (IMG, "../public_html/images"
or dienice("Can't open image directory: $!"
;
@allimages = readdir(IMG);
closedir (IMG);
##########################################################
#all ok up to here in browsers - but the rest won't run..#
##########################################################
#for each image file in the directory
foreach $imgfile (@allimages) {
$foundfile=0;
foreach $line (@products) {
chomp($line);
($letsection,$name,$title,$format,$price,$descript,$stockno,$section,$img,$weight,$date,$label,$catno) = split(/\|/,$line);
if ($imgfile eq $img) {
$foundfile = 1;
}
}
if ($foundfile == 0) {
$iftrue="0";
$iftrue = substr($imgfile, 0 , 2);
if ($iftrue eq "fe"
{
print "$imgfile<br>\n";
rename ("../public_html/images/$imgfile", "../public_html/remove/$imgfile"
;
}
}
}
print "</body></html>\n";
But, If I call it through my browser, I get a 'page cannot be displayed' message. Not even an error 500. I've come back to this after nearly 3 months with a clear head, and still can't figure out why..
Basically, the script scans a directory of image files against a flat file database.. if they're in the directory and not in the database it means they're redundant, and should be automatically transferred to a directory called 'remove'. That simple.
It's listed below - I've commented where it stops working in browsers.
Thanks for any help!
Matt.
#!/usr/local/bin/perl
#set content type
print "Content-type:text/html\n\n";
#HTML header
print "<html><head><title>w</title></head><body>Images to remove\n";
#check which products file to use
open (WHO,"data/whichfile.txt"
$whichfile = <WHO>;
close (WHO);
print "$whichfile is current file<br><br>\n";
#open current products file - store in @products
open (INFILE,"data/$whichfile"
@products = <INFILE>;
close (INFILE);
#open images directory - store in @allimages
opendir (IMG, "../public_html/images"
@allimages = readdir(IMG);
closedir (IMG);
##########################################################
#all ok up to here in browsers - but the rest won't run..#
##########################################################
#for each image file in the directory
foreach $imgfile (@allimages) {
$foundfile=0;
foreach $line (@products) {
chomp($line);
($letsection,$name,$title,$format,$price,$descript,$stockno,$section,$img,$weight,$date,$label,$catno) = split(/\|/,$line);
if ($imgfile eq $img) {
$foundfile = 1;
}
}
if ($foundfile == 0) {
$iftrue="0";
$iftrue = substr($imgfile, 0 , 2);
if ($iftrue eq "fe"
print "$imgfile<br>\n";
rename ("../public_html/images/$imgfile", "../public_html/remove/$imgfile"
}
}
}
print "</body></html>\n";