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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:08:40+00:00 2026-06-01T06:08:40+00:00

I am using get_headers() and I want to return the content length. In the

  • 0

I am using get_headers() and I want to return the content length. In the array below content length is key number 9, however I find that the content length is not always key number 9. I’m not sure why it is not always the same key? How do I search an array and always return the content length no matter what key it is? As I am using this in a function so the actual filesize of the file will be differen’t each time. My example code is below. Thanks in advance.

Array ( [0] => HTTP/1.0 200 OK [1] => Server: Apache [2] => Pragma: public [3] => Last-Modified: Sun, 01 Apr 2012 07:59:46 GMT [4] => ETag: "1333267186000" [5] => Content-Type: text/javascript [6] => Cache-Control: must-revalidate, max-age=0, post-check=0, pre-check=0 [7] => Expires: Sun, 01 Apr 2012 10:27:26 GMT [8] => Date: Sun, 01 Apr 2012 10:27:26 GMT [9] => Content-Length: 31650 [10] => Connection: close [11] => Set-Cookie: JSESSIONID=M0V4NTTVSIB4WCRHAWVSFGYKE2C0UIV0; path=/ [12] => Set-Cookie: DYN_USER_ID=2059637079; path=/ [13] => Set-Cookie: DYN_USER_CONFIRM=6c6a03988da3de6d704ce37a889b1ec8; path=/ [14] => Set-Cookie: BIGipServerdiy_pool=637871882.20480.0000; path=/ )

function headInfo($url) {
    $header = get_headers($url);
    $fileSize = $header[9];
    return array($header, $fileSize);
}
  • 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-01T06:08:42+00:00Added an answer on June 1, 2026 at 6:08 am

    http://php.net/get_headers

    The second parameter:

    If the optional format parameter is set to non-zero, get_headers() parses the response and sets the array’s keys.

    So, just pass 1 as the second parameter, and $header[‘Content-Length’] will be what you’ve after.

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

Sidebar

Related Questions

I am using interop and I want to get the list of all content
I'm making call to Alfresco Webscripts which return JSON. I do this using GET
I get a page using file_get_contents from a remote server, but I want to
I have a REST service built using Jersey. I want to be able to
I'm using SeperatedListAdapter available here: http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/ but I want to create a list with
I have a method that returns a PDF file using DOMPDF . It sends
I want to send an email with an attachment using the following code (Python
i found the code below in stackoverflow for resumeable file downloads : using System;
I want to write a server using a pool of worker threads and an
I asked a similar question last week but did not get an answer that

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.