File Upload Script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lastknight
    New Member
    • Jun 2007
    • 55

    File Upload Script

    hi all,
    i have seen a program from web that is used to upload a file from particular directory..
    My problem is that they have mentioned some file directory name in the program but when i am running the program, in the browser i am getting the directory is not valid..

    In this program i have not involved to do any part,but i need to know about this code..

    code for fileupload
    [CODE=perl]
    #!/usr/bin/perl

    print "content-type:text/html \n\n";
    print <<html_part;
    <html>
    <head>
    <script>
    function validate() {
    if(document.tes t.file.value==" ") {
    alert("file name cannot be empty");
    return;
    }
    document.test.s ubmit(true);
    }
    </script>
    </head>
    <body>
    <FORM name="test" ENCTYPE="multip art/form-data" ACTION="upload. cgi" METHOD="POST">
    <p>
    Please select a file to upload: <INPUT TYPE="FILE" NAME="file">
    <p>
    <INPUT TYPE="button" value="submit_f orm" onclick="valida te()">
    </FORM>
    </body>
    </html>
    html_part
    [/CODE]

    code for upload.cgi
    [CODE=perl]
    #!/usr/bin/perl
    print "content-type:text/html \n\n";

    use CGI;
    my $cgi = new CGI;

    my $file = $cgi->param('file' );
    $file =~ m/^.*(\\|\/)(.*)/;

    my $name = $2;

    open(LOCAL, ">../sample/$name") or die $!;
    while(<$file>) {
    print LOCAL $_;
    }
    print $cgi->header();
    print "$file has been successfully uploaded... thank you.\n";
    [/CODE]


    any help would be grateful..i can browse the file and attaching it, but it is not getting uploaded..
    will u give me answer for this...
    Last edited by miller; Jun 20 '07, 07:22 PM. Reason: Code tag and Reformatting
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    I assume this line is the problem:

    open(LOCAL, ">../sample/$name") or die $!;

    "../sample" is just that, it is an example only. You need to change that to a valid directory on your server.

    Comment

    • skyy
      New Member
      • May 2007
      • 109

      #3
      Hi...

      Make sure the folder exists in ur server and that the permission is allowed to write to the folder..

      Comment

      Working...