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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:08:44+00:00 2026-05-26T16:08:44+00:00

I have scoured the internet for code that can be used to allow users

  • 0

I have scoured the internet for code that can be used to allow users of my website to upload photos. I have tried a number of open source Perl codes, all with the same result: the new file uploaded to my server is blank!

Here is the code:

First, a webpage that asks for a file:

<form name="input" action="/cgi-bin/upload.pl" method="get" ENCTYPE="multipart/form-data">
Upload Photo:<input type="file" name="pic" /><BR>
<input type="submit" name="Submit" value="Submit Form" />

Now for the upload code:

#!/usr/bin/perl 
use CGI;
my $cgi = new CGI;
my $dir = "/home/mydomain/www/wwwboard/uploads";
my $file = $cgi->param('pic');
my $filename = $file;
$filename =~ s/^.*\\//;
$filename =~ s/^.*\///;
$filename =~ s/\s /_/g;

open(LOCAL, ">", "$dir/$filename") or die $!;
while(<$file>) {
    binmode LOCAL;
print LOCAL $_;
}
close(LOCAL);
print "Content-type: text/html\n\n";
print "$file has been successfully uploaded... thank you.\n";

I’m not a Perl expert, but it seems to me the problem is that the variable $file = $cgi->param(‘pic’); is only picking up the basename of the file-handle from the user’s computer. For example, when I try to upload a file called “/home/nick/Pictures/photo.JPG”, the message I get from the server says “photo.JPG has been successfully uploaded… thank you.”. Maybe that’s not the problem, I don’t know…

I get the same result using firefox and chrome. The permissions for the uploads folder is 777.

I know the security on this code is weak. I can get to that later. right now I just want to see it work.

  • 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-26T16:08:45+00:00Added an answer on May 26, 2026 at 4:08 pm

    If you google perl cgi file upload the first link is to a tutorial that shows you exactly how to do this: http://www.sitepoint.com/uploading-files-cgi-perl/

    • You’re doing a get instead of a post on your form
    • You’re not reading the file from the CGI object, which is accessed via $cgi->upload('pic')
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have scoured the internet looking for an answer to this question and can't
I have scoured the internet but can't find an answer to this : I'm
I have scoured the internet to find which CMS's run on CloudSites and the
I have scoured for 2 hours now across the internet, I have found courses
I have scoured the internet and am at a loss as to why my
I've scoured the internet and have yet to find a solution. Help me Stack-Overflow-Kenobi,
I have scoured the internet looking for a solution to this and I am
I have a question with fluent interfaces. We have some objects that are used
I have scoured the internet looking for a good tutorial or posting about having
I have scoured the Internet for an answer to this. I have an array

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.