Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: CGI Question

by Shendal (Hermit)
on Sep 26, 2000 at 00:41 UTC ( [id://33959]=note: print w/replies, xml ) Need Help??


in reply to CGI Question

First, consider <CODE> tags instead of <PRE>. It word wraps.

If I understand you correctly, you don't want perl to interpret what you're writing to the file. In that case, use single quotes (') instead of double-quotes ("). You may also want to use something like <<EOF to write a bunch of output.

Here's what your code may end up looking like:

#####Create Perl upload script open(FILE, ">$basedir$q_brieftitle/upload.cgi") || &diedebug("$header Could not create file " . "$basedir$q_brieftitle/upload.cgi: $! . " . "It's possible 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 your quizzes and " . "answerfiles by hand. :( $footer"); flock(FILE, 2); &get_date; # Note the single quotes in the next line... print FILE <<'EOF'; #!/usr/bin/perl $basedir = "/home/sites/stuff/users/web/up2"; $allowall = "yes"; $theext = ".gif"; $donepage = "http://www.yourpage.com/"; ## 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"; 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);

Cheers,
Shendal

Replies are listed 'Best First'.
RE: Re: CGI Question
by koacamper (Acolyte) on Sep 27, 2000 at 01:52 UTC
    Thank you! That did the trick! Which brings me to another question...how can I adjust the script so that the $basedir will always point to the directory where the script is newly written? Or possibly add a $subdir variable? If so, how can I accomplish this?

    thank you
    koa

    i want to learn
      Ummm, I'm not exactly sure what $basedir is supposed to mean. Perhaps something like this will show you a solution?

      #!/usr/bin/perl -w use strict; # always use File::Basename; my $prog = $^X; my $basedir = dirname($prog); print "prog : $prog\n"; print "basedir: $basedir\n";
      Which outputs:
      prog : /usr/bin/perl basedir: /usr/bin

      Cheers,
      Shendal

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://33959]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-03-29 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found