in reply to Problem with file upload CGI script

just another thing i spotted:
while (<$filename>) { ... } while ($bytesread=read($filename,$buffer,1024)) {
after the first while $filename will be at eof and return undef.