Loading ...
Sorry, an error occurred while loading the content.
 

program example

Expand Messages
  • Bob
    Good morning I bought the book CGI Programming 101. I could really use the example in it for the websites I do so people could each upload photos to the server
    Message 1 of 1 , Apr 28, 2002
      Good morning
      I bought the book CGI Programming 101. I could really use the example
      in it for the websites I do so people could each upload photos to the
      server for all to see. I am having a hard time trying to figure out
      where the files would go, what folder they are saved in once they get to
      the server and if this could be changed to different folders. I can
      understand alot of the code but don't see anything about where the files
      go.
      Thank you
      Bye
      Bob

      http://cgi101.com/class/ch17/upload.txt
      http://cgi101.com/class/ch17/upload.html



      #!/usr/bin/perl
      use CGI;

      $q = new CGI;

      print $q->header, $q->start_html(-title=>"Upload
      Results",-bgcolor=>"white");
      print $q->h2("Upload Results");

      $file = $q->param("upfile");
      if (!$file) {
      print "Nothing uploaded?<p>\n";
      } else {
      print "Filename: $file<br>\n";
      $ctype = $q->uploadInfo($file)->{'Content-Type'};
      print "MIME Type: $ctype<br>\n";
      open(OUT,">/tmp/outfile") or dienice("Can't open outfile for
      writing: $!");
      $flen = 0;
      while (read($file,$i,1024)) {
      print OUT $i;
      $flen = $flen + 1024;
      if ($flen > 5120000) {
      close(OUT);
      dienice("Error - file is too large. Save aborted.<p>");
      }
      }
      close(OUT);
      print "Length: ",$flen/1024,"Kb<p>\n";
      print "File saved!<p>\n";
      # display the image. this only works because we have a symlink from
      # tmp.gif/jpeg in the current directory, to /tmp/outfile.
      if ($ctype eq "image/gif") {
      print "Here's what you sent:<p>\n";
      print "<img src=\"tmp.gif\" border=1><p>\n";
      } elsif ($ctype eq "image/jpeg") {
      print "Here's what you sent:<p>\n";
      print "<img src=\"tmp.jpg\" border=1><p>\n";
      }
      }

      $q->end_html;

      sub dienice {
      my($msg) = @_;
      print "<h2>Error</h2>\n";
      print "$msg<p>\n";
      exit;
      }




      --
      Bye
      Bob Bob Axmear 208 2nd St Ne Waukon, Ia 52172
      http://groups.yahoo.com/group/the_refuge
      Websites http://gardensights.com
      Hosta Library http://hostalibrary.org/
    Your message has been successfully submitted and would be delivered to recipients shortly.