Hello,
I hope this is a simple question for you PERL Guru's...I've been working a script(with lots of help from all of you) that currently does the following:
1. creates a sub-directory
2. writes a .htaccess file in the new dir
3. writes a .htgroup file in the new dir
4. writes a .htpasswd file in the new dir
5. writes a upload.html file in the new dir
6. writes a upload.pl file in the new dir
7. chmods the .pl file 755
the problem that has me scratching my head is, how can I set the script to automatically adjust the $basedir in the cgi script to match the current, newly made, sub-directory?
Here is the part of the script that's driving me mad:
# Create PERL file...
open(FILE, ">$basedir$q_brieftitle/upload.pl") || &diedebug("$header C
+ould not create file $basedir$q_brieftitle/answerfile: $! . It's poss
+ible that your web server will not let me create files even if I own
+the directory. If you have chmodded $basedir$q_brieftitle/ to 777 and
+ you are still getting this message, then you will need to create you
+r files by hand. :( $footer");
flock(FILE, 2);
&get_date;
print FILE <<'EOF';
#!/usr/bin/perl
$basedir = "/path/to/base/dir/";
$allowall = "yes";
$theext = ".gif";
$donepage = "up2.html";
## DO NOT EDIT OR COPY BELOW THIS LINE ##
use CGI;
$onnum = 1;
while ($onnum != 11) {
my $req = new CGI;
my $file = $req->param("FILE$onnum");
if ($file ne "") {
my $fileName = $file;
$fileName =~ s!^.*(\\|\/)!!;
$newmain = $fileName;
if ($allowall ne "yes") {
if (lc(substr($newmain,length($newmain) - 4,4)) ne $theext){
$filenotgood = "yes";
}
}
if ($filenotgood ne "yes") {
open (OUTFILE, ">$basedir/$fileName");
print "$basedir/$fileName<br>";
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE);
}
}
$onnum++;
}
print "Content-type: text/html\n";
print "Location:$donepage\n\n";";
EOF
close(FILE);
The EOF leaves the code alone and doesn't crash the main program...but I need to learn a way to make the $basedir the same as the $basedir$q_brieftitle in the above code.
Thank you
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.