Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: CGI Question

by Shendal (Hermit)
on Sep 26, 2000 at 00:41 UTC ( #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 = ""; ## 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);


Comment on Re: CGI Question
Download Code
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 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

    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


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2016-02-14 13:36 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (470 votes), past polls