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

Can we read the header information of a file in PHP to determine the
How can I determine the name of the Bash script file inside the script
How can I get the file name of the image used in a GtkImage
Can a Windows batch file determine its own file name? For example, if I
This file name must be recognisable like README/INSTALL/AUTHORS/COPING/etc. So user can easily found them
Given a DFS path, how can I programatically determine which physical file server it
How can I determine the IP of my router/gateway in Java? I can get
How can you determine the performance consequences of your PHP code if you are
Can I use the PHP code below if the PDF file is not on
Given a path to a file or directory, how can I determine the mount

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.