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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:17:45+00:00 2026-05-14T07:17:45+00:00

Hi I have a script that creates a file and stores it on the

  • 0

Hi I have a script that creates a file and stores it on the server. The file is encoded in UTF-8 and is a kind of xml file for the cmap software.

If i open the file directly from the server then there is no problem and the file can be read.

I am forcing a download of this file when a user goes to a specific url. After such a download, the file is unreadable by the cmap software. I have to go into my text editor (notepad++) and change the encoding from UTF-8 to UTF-8 without BOM.

Am I sending the wrong headers? Is php doing something to the file when it is downloading it?

Any advice on this would really be appreciated.

Cheers
Drew

EDIT

Sorry, there is a lot of code involved in a couple of different classes. I have included the code i am using to send the file to the browser:

function exportCMAP()
{   
    $serializer = new Serializer();
    $serializer->serializeCmap();

    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=export.cxl");
    header("Content-Type: x-cmap/text-xml");
    header("Content-Transfer-Encoding: binary");

    readfile("temp/export.cxl");
}

If the code that generates the xml (using XMLWriter) is required i can post that too.

EDIT

As requested here is the code where the xml is being produced – it is in another class:

        function serializeCmap()
    {

        $storeManager = new StoreManager();         
        $linkedNodes = $storeManager->getLinkedNodes();

        $namespaces = Array();

        $writer = new XMLWriter();

        $writer->openMemory();
        $writer->setIndent(4); 

        $writer->startDocument('1.0', 'utf-8');

            $writer->startElement('cmap');

                $writer->writeAttribute('xmlns', 'http://cmap.ihmc.us/xml/cmap/');
                $writer->writeAttribute('dc', 'http://purl.org/dc/elements/1.1/');

            $writer->startElement('res-meta');

                $writer->writeElement("dc:title", "Full schema for Cmap");
                $writer->writeElement("dc:description", "Description Goes Here");

            $writer->endElement();  

            $writer->startElement('map');

                $writer->startElement('concept-list');

                    foreach($linkedNodes['nodes'] as $node=>$id) {

                        $writer->startElement('concept');

                            $writer->writeAttribute("id", $id);
                            $writer->writeAttribute("label", $node);

                        $writer->endElement();
                    }

                $writer->endElement();

                $writer->startElement('linking-phrase-list');

                    foreach($linkedNodes['phrases'] as $phrase=>$id) {

                        $writer->startElement('linking-phrase');

                            $writer->writeAttribute("id", $id);
                            $writer->writeAttribute("label", $phrase);

                        $writer->endElement();
                    }

                $writer->endElement();

                $writer->startElement('connection-list');

                    foreach($linkedNodes['connections'] as $key=>$val) {

                        $writer->startElement('connection');

                            $writer->writeAttribute("from-id", $val['from']);
                            $writer->writeAttribute("to-id", $val['phrase']);

                        $writer->endElement();

                        $writer->startElement('connection');

                            $writer->writeAttribute("from-id", $val['phrase']);
                            $writer->writeAttribute("to-id", $val['to']);

                        $writer->endElement();
                    }

                $writer->endElement();

            $writer->endElement();

        $writer->endElement();

        $writer->endDocument();

        file_put_contents("temp/export.cxl",$writer->outputMemory());
    }
  • 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-14T07:17:45+00:00Added an answer on May 14, 2026 at 7:17 am

    You should add two important things:

    1. Test if the HTTP header has not been sent yet, and
    2. ensure that there is no more output than the one of readfile.

    So try this:

    function exportCMAP() {
        if (headers_sent()) {
            // HTTP header has already been sent
            return false;
        }
        // clean buffer(s)
        while (ob_get_level() > 0) {
            ob_end_clean();
        }
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=export.cxl");
        header("Content-Type: x-cmap/text-xml");
        header("Content-Transfer-Encoding: binary");
        readfile("temp/export.cxl");
        // avoid any further output
        exit;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bash script that creates a Subversion patch file for the current
I have written a CGI script that creates an image dynamically using GET data.
I have created a PHP-script to update a web server that is live inside
I have a script that retrieves objects from a remote server through an Ajax
I have a script that takes a table name and generates a control file
I have a simple PowerShell script that uses WMI to create a web site
I have a migration that runs an SQL script to create a new Postgres
I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example),
I have a script that checks responses from HTTP servers using the PEAR HTTP
I'm using SQL*Plus 9.2 on Oracle 10g enterprise. I have created some scripts 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.