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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:03:37+00:00 2026-05-18T01:03:37+00:00

how can i determine the file name in header when i get with php.

  • 0

how can i determine the file name in header when i get with php. lock at this:

<?php
/*
This is usefull when you are downloading big files, as it
will prevent time out of the script :
*/
set_time_limit(0);
ini_set('display_errors',true);//Just in case we get some errors, let us know....

$fp = fopen (dirname(__FILE__) . '/tempfile', 'w+');//This is the file where we save the information
$ch = curl_init('http://www.example.com/getfile.php?id=4456'); // Here is the file we are downloading

/*
    the server get me an header 'Content-Disposition: attachment; filename="myfile.pdf"'

    i want get 'myfile.pdf' from headers. how can i get it ?
*/

$fileNameFromHeader = '?????????????';

curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);

// rename file
rename(dirname(__FILE__) . '/tempfile', dirname(__FILE__) . $fileNameFromHeader);
  • 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-18T01:03:37+00:00Added an answer on May 18, 2026 at 1:03 am

    Create a callback that reads headers, and parse them yourself. Something like:

    function readHeader($ch, $header)
    {
              global $responseHeaders;
              $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
              $responseHeaders[$url][] = $header;
          return strlen($header);
    }
    
     ... curl stuff ...
     // if you need to call a class method use this:
     // curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$this,'readHeader'));
     // for a non class method use this
     curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'readHeader');
     $result = curl_exec($ch);
    
     // all headers are now in $responseHeaders
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get the filesize of a file located in the assets
I'm trying to add a file upload script in php to a website I'm
How can options/arguments determine which function is chosen during program execution? For the example
For example I have such array: name[0] = Griffin; name[1] = David; name[2] =
I have 3000 binary files (each of size 40[MB]) of known format (5,000,000 'records'
Problem Background I am currently working on a camel based ETL application that processes
In the course of converting a blog from Blogger to WP and running a
I'm setting up an instance on ec2 using the rubber deployment tool. I need
I'm a beginner with JS. I am working with some JavaScript on a site,
While using the Google code website, I have tried using the command prompt 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.