Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:17:15+00:00 2026-06-12T11:17:15+00:00

I am trying to do a simple upload of a .csv file and save

  • 0

I am trying to do a simple upload of a .csv file and save it on my server. I’m not an expert in HTML or Perl, but due to client constraints this is what I must do.

Here is the HTML:

<form action="/path/to/service" target="_self" method="POST" enctype="multipart/form-data">
File: <input type="file" name="attachment" size="50">
<SUBMIT_RESET Upload File>
</form>

The Perl code looks like this:

    my $sql = "SELECT NOW()";
    my $date = $DB->get_field($sql);

    my ($path, $ext) = split(/\./, $in{'attachment'});
    my @pathParts = split(/\//, $path);            
    my $filename = $pathParts[@pathParts - 1] . " - " . $date;

    if ($ext eq "csv") {                

        open (OUTFILE, ">", "$datadir/imports/" . $filename . "." . $ext);

        while (read($in{'attachment'}, $buffer, 1024)) {
            $file .= $buffer;
        }
        print OUTPUT $file;
        close (OUTFILE);
    }

Can anyone please give me some direction as to what I’m doing wrong. I get the file located at the correct path, but it’s always empty.

Now, the code base I’m dealing with here is horrible and I cannot use strict.

Suggestions?

EDIT1:
To attempt to answer how $in{‘attachment’} is populated I’ve included a snippet of code of how forms are handled.

if ($ENV{‘CONTENT_TYPE’} =~ m#^multipart/form-data#) {
my $cgi = new CGI;
my @names = $cgi->param;

        foreach $name (@names) {
            my @value = $cgi->param($name);
            if (scalar(@value) > 1) {
                foreach $val (@value) {
                    $in{$name} .= $val."\0";
                }
                $in{$name} =~s/\\0$//;
            } else {
                my $value = $cgi->param($name);
                #my $value = join "\0", @value;
                $in{$name} = $value;
            }
            #my $value = $cgi->param($name);
            #my $value = join "\0", @value;
            #$in{$name} = $value;
        }

EDIT2:

To summarize the solution provided by ikegami…

I missed that the file handles were different for the read and print statements – OUTFILE and OUTPUT. Clearly that is completely a novice mistake and for that I apologize!

Best wishes to all who tried to help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:17:16+00:00Added an answer on June 12, 2026 at 11:17 am

    You shouldn’t be using global variables. If your file handles had been lexical variables (supported since 2000!) and if you had been using use strict; (also supported since 2000, if not earlier!), you would have found the problem:

    You’re not using the right variable in your print call.

    open (OUTFILE, ">", "$datadir/imports/" . $filename . "." . $ext);
    print OUTPUT $file;
    

    When I discovered the problem, I was about to recommend you find out what error you actually got:

    open(my $OUTFILE, ">", "$datadir/imports/$filename.$ext")
       or die $!;
    
    while (1) {
       my $rv = read($in{'attachment'}, my $buf, 1024);
       die $! if !defined($rv);
       last if !$rv;
    
       print $OUTFILE $buf
          or die $!;
    }
    
    close($OUTFILE)
       or die $!;
    

    (I was going to hypothesise that the error was “Bad file descriptor” due to passing something that isn’t a file handle to read.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to upload a csv file to a database through simple html
I'm trying to do a simple file upload page but keep getting can't convert
I'm trying to have a simple form with a file upload, but it isn;t
I am trying to implement a simple file upload, but having some troubles. When
I'm trying to do a simple file upload using objective c and NSUrlRequest. My
I've been trying to do simple file uploads but I am unable to find
I'm trying to upload a file to my Spring server running on Tomcat7. It's
I am trying to make a simple upload file system, and this is my
I'm trying to create a simple file upload form for my website. I'm using
I'm trying to upload a file (like image file) into a Restful server like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.