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

  • Home
  • SEARCH
  • 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 1100547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:53:51+00:00 2026-05-17T00:53:51+00:00

I’m using json to open the user popup. I used to use basename( $_FILES[‘userfile’][‘name’]

  • 0

I’m using json to open the user popup.
I used to use basename( $_FILES['userfile']['name'] ) on php, how to do that on perl?

Server side code:

#!/usr/bin/perl
use CGI;

print "Content-type: text/html; 
Cache-Control: no-cache;
charset=utf-8\n\n";

@allowedExtensions =("jpg","tiff","gif","eps","jpeg","png");

my $q = CGI->new();

my $filename = $q->upload('userfile');

print "file name is $file_name";

Client side code:

var post_obj = new Object();

new AjaxUpload('upload_attachment_button', {
    action: 'upload.cgi',
    type: "POST",
    data: post_obj,

    onChange: function() {},
    onSubmit: function() {
      $("#upload_attachment_button").addClass('ui-state-disabled');
      $("#upload_proj_message").html('<span> class="loading">uploading...</span>');
    },
    onComplete: function(file, response) {
      $("#upload_attachment_button").removeClass('ui-state-disabled');
      alert(response);
    }
});
  • 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-17T00:53:51+00:00Added an answer on May 17, 2026 at 12:53 am

    Looks like you trying to get name of the file uploaded by user. If you are using CGI module, then here is solution:

    use CGI;
    my $q = CGI->new();
    
    my $filename = $q->param('userfile'); ## retrive file name of uploaded file
    

    From the manual:

    Different browsers will return slightly different things for the name. Some browsers return the filename only. Others return the full path to the file, using the path conventions of the user’s machine. Regardless, the name returned is always the name of the file on the user’s machine, and is unrelated to the name of the temporary file that CGI.pm creates during upload spooling (see below).

    Update:

    Sorry, didn’t noticed it before. Please add use strict; at the begining of the script. It’ll force you to declare all variables. You’ll see mistype in print statement:

    print "file name is $filename"; ## must be $filename
    

    To declare @allowedExtensions just add my before first use:

    my @allowedExtensions =("jpg","tiff","gif","eps","jpeg","png");
    

    Also I believe that you don’t need ; at the end of lines when you print HTTP headers:

    print "Content-type: text/html 
    Cache-Control: no-cache
    charset=utf-8\n\n";
    

    And please always use strict. It’ll save you tons of time in future.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.