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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:29:13+00:00 2026-06-06T16:29:13+00:00

I have a perl script URL which gives me a ZIP file, it processes

  • 0

I have a perl script URL which gives me a ZIP file, it processes the data and dynamically set the Content-Type to 'application/zip' in the http-header.

Perl code looks like this:

WPHTTPResponse::setHeader( 'Content-disposition', 'attachment;filename="test.zip"');
WPHTTPResponse::setHeader( 'Content-type', 'application/zip');  
print $result;

In frontend, I am using this script direct in HREF:

      <a href="/script">Download</a>

But I have a requirement of showing an alert message if $result is NULL in perl script.

What I am thinking is: I will send the file with Content-Type=>application/zip if the $result if not null, otherwise I will send the JSON response with error message that there is no file to download.

For this I would need to dynamically check the content type using JS:

$.ajax({
  url: '/script',
  data: {....},
  success: function(response) {
     if(response.contentType == 'application/zip'){
        //download using javascript
     }
     else{
        $.parseJSON(response);
        alert(response.msg);
     }
  }
});

I’d appreciate any help.

  • 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-06T16:29:14+00:00Added an answer on June 6, 2026 at 4:29 pm

    Although your method should work, this is a case where using using HTTP error codes would probably be a good choice.

    Depending on why $result is null one of these should be appropriate.

    400 Bad Request
    406 Not Acceptable
    410 Gone
    

    This would make your code slightly more ‘obvious’ as you would be using the HTTP status for exactly what it was meant for, rather than re-implementing the exact same thing in a proprietary way in your code. IMHO it would also make your code a bit easier to maintain as it would separate the success from the error.

    You can still include JSON as part of the error response, to be able display information about exactly why the request didn’t result in any data being returned to the client.

    btw I’d avoid using 404 as the error code, even though it is technically the most ‘appropriate’ code just because it would cause confusion if a real 404 error occurred.

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

Sidebar

Related Questions

I have a perl script (or any executable) E which will take a file
I have an .htaccess file which calls a perl script if certain conditions are
I have a Perl script which maps two drives, and then proceeds to copy
I have a Perl script that uses WWW::Mechanize to read from a file and
I have a Perl script called replaceUp: #!/usr/bin/perl search=$1 replace=$2 find . -type f
I have a Perl script which nests foreach loops as seen below. It takes
Have a perl script that needs to process all files of a certain type
I have a Perl script inserting data into Postgres according to a pipe delimited
I have a Perl script that gets data from a MySQL database on one
I have a Perl script (standalone program) which contains some subs I'd like to

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.