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 7655159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:26:30+00:00 2026-05-31T12:26:30+00:00

I am able to create my directory but I cannot seem to place the

  • 0

I am able to create my directory but I cannot seem to place the file in the directory.

#!/usr/bin/perl

use Cwd;
use CGI;

my $dir = getcwd();
print "Current Working Directory: $ dir\n";

my $photoDir = "$dir/MyPhotos";

mkdir $photoDir
        or die "Cannot mkdir $photoDir: $!"
        unless -d $photoDir;
        
        
my $query = new CGI;
my $filename = $query->param("Photo");
my $description = $query->param("description");

print "Current filename: $filename\n";

my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' ); $filename = $name . $extension;
print $filename;
my $upload_filehandle = $query->upload("Photo");



open ( UPLOADFILE, ">$photoDir/$filename" )
 or die "$!"; 
binmode UPLOADFILE; 

while ( <$upload_filehandle> ) 
{ print UPLOADFILE; } 
close UPLOADFILE;

The CGI stack trace shows no errors but the log shows there is no output

LOG: 5 5020-0:0:0:0:0:0:0:1%0-9: CGI output 0 bytes.
  • 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-05-31T12:26:31+00:00Added an answer on May 31, 2026 at 12:26 pm

    Update: This answer is outdated, today you will get an IO::File compatible handle directly:

    # undef may be returned if it's not a valid file handle
    if ( my $io_handle = $q->upload('field_name') ) {
        open ( my $out_file,'>>','/usr/local/web/users/feedback' );
        while ( my $bytesread = $io_handle->read($buffer,1024) ) {
            print $out_file $buffer;
        }
    }
    

    Please see the updated documentation.


    Original answer:

    CGI.pm manual suggests this path to saving uploaded files. Try this additional check and write method and see if it helps.

         $lightweight_fh  = $q->upload('field_name');
    
         # undef may be returned if it's not a valid file handle
         if (defined $lightweight_fh) {
           # Upgrade the handle to one compatible with IO::Handle:
           my $io_handle = $lightweight_fh->handle;
    
           open (OUTFILE,'>>','/usr/local/web/users/feedback');
           while ($bytesread = $io_handle->read($buffer,1024)) {
             print OUTFILE $buffer;
           }
         }
    

    Also make sure you have your HTML form has required type like this: <form action=... method=post enctype="multipart/form-data">

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

Sidebar

Related Questions

for some reason I'm able to create the outputfile inside my /tmp directory but
I have been able to create ASPX pages without the code behind, but I
You should be able to create a generic form: public partial class MyGenericForm<T> :
Has anyone been able to create Container-Specific Master Pages for Safari or Chrome? I
I am able to create and execute a DTS package that copies tables from
I am able to create a UIImage from a Core Animation layer using the
I am able to create a connection to a local sqlite3 database ( Using
I am able to create alternate dictation grammars using the dictation resource kit or
I am not able to create a jsTree inside of a jQuery UI tab.
I need to be able to create basic MS Project items (tasks, projects, resources,

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.