CGI upload creates empty file on server?

From: Kristian (kristian_at_detandetfirma.dk)
Date: 10/21/03


Date: 21 Oct 2003 00:27:54 -0700

The script below uploads the selected file and creates it on the
server in the right directory and all looks fine. But the file is
empty, it contains nothing...

HTML FORM:
<form name="foo" method="post" action="../upload_image.pl"
target="_self" enctype="multipart/form-data">
<input type="file" name="file"><input type="text"
name="filename"></form>

Perl script:

#!/usr/bin/perl

use CGI;
use Cwd;

                #print "Content-type: text/html \n\n";

#Setup query from cgi
my $cgi = new CGI;

#Setup upload directory
$uploaddir = "/client_image_uploaddir";
$file = $cgi -> param("file");
        $file =~ s/.*[\/\\](.*)/$1/;
$filename = $cgi -> param("filename");
$datestr = time;

        #Handle the upload
        open FHUP, ">$uploaddir/$file" or die;
                binmode FHUP;
                        
                undef $Buffer;
                        while( read( $file, $Buffer, 1024 ) ){
                                print FHUP $Buffer;
                        }
        close (FHUP);
        
        print $cgi -> header();
                
                print "<h3>Filen '$filename' blev uploaded!</h3>";
                print "<img src=client_image_uploaddir/$file alt=$filename> ";
                print "<a href=\"javascript:void(history.back());\">Tilbage</a> <a
href=\"javascript:void(window.close());\">Luk vindue</a>";
        
I also tried without 'buffering' and the result is the same, file is
created but with no content.

Any ideas?

/Kristian



Relevant Pages

  • Re: Key-passing from PHP to TCL CGI script - how is it done (web security issue)?
    ... TCL v.8.3 ... set hasEnteredTrivia 0 ... # NEW 8/7/2004 USE PHP (AS CGI) TO CHECK IF USER IS ATTEMPTING TO ENTER ... # USE REMOTE PHP SCRIPT TO CHECK FOR REPOSTING ...
    (comp.lang.tcl)
  • Re: Changing Passwords through the web (fwd)
    ... I use a CGI script that uses the poppassd and python ports on my small ... alert; ...
    (FreeBSD-Security)
  • Re: Help with a stragegy for diagnosis
    ... I have a Perl CGI that has work for years. ... first failure and before the second. ... A strategy would be to write tests for the script until you get the same ...
    (comp.lang.perl.moderated)
  • Re: Recommend PHP-Based Dashboard?
    ... and this is to illicite a response from php developers in a php usenet group trying to foster some kind of fear in us all that you may change your mind and go java or windows or mac? ... as i run true cgi scripts from the cgi exe *all the time* from the command-line, i assure you that you're wrong. ... the above explicitly states that i must use a feature of cgi in order to be considered a cgi script. ...
    (comp.lang.php)
  • Re: CGI email script
    ... > I recently started playing with Python CGI, and I was happy that my ... > I'm trying to write a basic Python email CGI script to send email ... web server runs an SMTp server as well this will work. ...
    (comp.lang.python)