Calilo has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Uploading files to server
by hopes (Friar) on Oct 15, 2001 at 03:43 UTC
    Hi monk,
    You can use the cgi.pm module.
    See the documentation for detais
    Greets

    Hopes

      ok

      #!/usr/local/bin/perl use CGI; $q = new CGI; $file = $q->param('file'); ##### $up = $q->upload("$file"); while (<$up>) { print; } exit:

      i have this one , but it aint work, it shows "500 error"

      there must be something missing, what??

      pics of peolple, "JPG", its for a site About my city, buissnes listing, partys, disco, peolple,

      thath kind of stuff

      Calilo
        Hi again,
        try exit; instead exit:
        You have to write html headers too
        It is also recommended to use strict and warnings.
        #!/usr/local/bin/perl -w use CGI; use strict; my $q = new CGI; print $q->header; print $q->start_html("Example"); my $file = $q->param('file'); my $up = $q->upload("$file"); while (<$up>) { print; } exit;
        Last, but not less important, check the permissions. Maybe you shouldn't be able to write.
        Check the error 500 with Netscape. It brings useful information about the error.
        It is probably syntax error

        Hope this help
        Hopes
Re: Uploading files to server
by Calilo (Initiate) on Oct 15, 2001 at 02:35 UTC
    i got to this:
    # Read a text file and print it out while (<$filename>) { print; } # Copy a binary file to somewhere safe open (OUTFILE,">>/usr/local/web/users/feedback"); while ($bytesread=read($filename,$buffer,1024)) { print OUTFILE $buffer; }

    but im not sure this is all i need, i seem to small for me,

    i need it for uploaing pics, actually.

    so?? help available?

      Hmmm, what kind of pics?
Re: Uploading files to server
by Calilo (Initiate) on Oct 15, 2001 at 04:40 UTC
    oky

    that worked thanks alot

    now if im correct i only have to add a part that copys the

    file to a safe place so is'nt deleted after uploaded, right??

    # Read a text file and print it out while (<$file>) { print; # Copy a binary file to somewhere safe open (OUTFILE,">>/usr/local/web/users/feedback"); while ($bytesread=read($file,$buffer,1024)) { print OUTFILE $buffer; } }
    is it this???

    Calilo

    thanks alot Hopes
      You don't need the first part:
      while (<$file>) { print;

      Just the second part:

      # Copy a binary file to somewhere safe open (OUTFILE,">>/usr/local/web/users/feedback"); while ($bytesread=read($file,$buffer,1024)) { print OUTFILE $buffer; } close(OUTFILE); #Always make sure to close the file or it won't work.

      Also make sure that the directory you write to has write permissions by the webserver and finally make sure the HTML form you have to do the uploading has type="multipart/form-data" in the form tag.

      Hope that helps. UPDATE: That should be enctype="multipart/form-data"
Re: Uploading files to server
by Calilo (Initiate) on Oct 16, 2001 at 07:08 UTC
    ok it somehow works. it creates the file, but it seems to be empty,
    #!/usr/bin/perl -w use CGI; use strict; my $q = new CGI; print $q->header; print $q->start_html("File Uploaded"); my $file = $q->param('file'); my $up = $q->upload("$file"); while (<$up>) { print; } my $buffer; my $bytesread; # Copy a binary file to somewhere safe open (OUTFILE,">>/var/www/html/fotos/misc/try1.txt"); while ($bytesread=read($file,$buffer,1024)) { print OUTFILE $buffer; } close(OUTFILE); #Always make sure to close the file or it won't work. exit;

    what may it be???

    Calilo