Hello, Could you answer a question for me concerning a script
that I'm currently working on? The script in question
is one that currently does the following:
~Creates a new directory
~Writes .htaccess, .htpasswd, and .htgroup files to protect the directory
~Writes an upload (HTML) file.

I would also like the script to write the upload.cgi program but am running into difficulties with the variables conflicting with the main program. Is there a way to have the script written to the newly created directory without conflict? Is there a way to "Shield" the $variables?

Here is the portion of the script that has me stumped:
#####Create Perl upload script open(FILE, ">$basedir$q_brieftitle/upload.cgi") || &diedebug("$header +Could not create file $basedir$q_brieftitle/upload.cgi: $! . It's pos +sible 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 an +d you are still getting this message, then you will need to create yo +ur quizzes and answerfiles by hand. :( $footer"); flock(FILE, 2); &get_date; print FILE (" #!/usr/bin/perl \n"); print FILE (" $basedir = \"/home/sites/stuff/users/web/up2\"; \n"); print FILE (" $allowall = \"yes\"; \n"); print FILE( " $theext = \".gif\"; \n"); print FILE (" $donepage = \"http://www.yourpage.com/\"; \n"); print FILE (" ## DO NOT EDIT OR COPY BELOW THIS LINE ## \n +"); print FILE (" use CGI; \n"); print FILE (" $onnum = 1; \n"); print FILE (" while ($onnum != 11) { \n"); print FILE (" my $req = new CGI; \n"); print FILE (" my $file = $req->param(\"FILE$onnum\"); \n"); print FILE (" if ($file ne \"\") { \n"); print FILE (" my $fileName = $file; \n"); print FILE (" $fileName =~ s!^.*(\\|\/)!!; \n"); print FILE (" $newmain = $fileName; \n"); print FILE (" if ($allowall ne \"yes\") { \n"); print FILE (" if (lc(substr($newmain,length($newmain) - 4,4)) ne $t +heext){ \n"); print FILE (" $filenotgood = \"yes\"; \n"); print FILE (" } \n"); print FILE (" } \n"); print FILE (" if ($filenotgood ne \"yes\") { \n"); print FILE (" open (OUTFILE, \">$basedir/$fileName\"); \n"); print FILE (" print \"$basedir/$fileName<br>\"; \n"); print FILE (" while (my $bytesread = read($file, my $buffer, 1024)) + { \n"); print FILE (" print OUTFILE $buffer; \n"); print FILE (" } \n"); print FILE (" close (OUTFILE); \n"); print FILE (" } \n"); print FILE (" } \n"); print FILE (" $onnum++; \n"); print FILE (" } \n"); print FILE (" print \"Content-type: text/html\n\"; \n"); print FILE (" print \"Location:$donepage\n\n\"; \n"); close(FILE);
Any help would be greatly appreciated!

Thank you,
koa

In reply to CGI Question by koacamper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.