Re: Creating a File in Memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Can't help with your main problem, however I find it easier to write
the likes of :

$kml_string = $kml_string . "<Document>";

as:

 $kml_string .= "<Document>";

;-)

On 9/7/07, John Schattel <John.Schattel@xxxxxxxx> wrote:
> Hello All,
>
> I am trying to zip data in a PHP program using the following code.  The
> resulting file (ndfdViaPipe.kmz) is zip'ed but the data in the archive
> lacks a file name.  So when a program like Google Earth tries to process
> the file, it fails.  When I bring ndfdViaPipe.kmz into WinZip, the file
> has no name but can otherwise be extracted just fine.  Once extracted,
> Google Earth can process the file.  Does anyone know how I might add the
> "file name" information to the ndfdViaPipe.kmz?  The reason I'm trying
> to use pipes is to avoid creating a file with the dynamically created
> data in $kml_string.  The plan is to send $kmz_content out in a SOAP
> service message with the payload as base64 encoded file.  If there is a
> better way to accomplish this I am certainly open to suggestions.
>
> In advance, thanks for any help you care to offer.
>
> John
>
> <?php
>
> $kml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
> $kml_string = $kml_string . "<kml
> xmlns=\"http://earth.google.com/kml/2.1\";>";
> $kml_string = $kml_string . "<Document>";
> $kml_string = $kml_string . "   <name>National Digital Forecast Database
> Data</name>";
> $kml_string = $kml_string . "   <open>1</open>";
> $kml_string = $kml_string . "  <Schema parent=\"Placemark\"
> name=\"NdfdData\">";
> $kml_string = $kml_string . "    <SimpleField type=\"wstring\"
> name=\"UOM\"></SimpleField>";
> $kml_string = $kml_string . "    <SimpleField type=\"wstring\"
> name=\"ValidTime\"></SimpleField>";
> $kml_string = $kml_string . "    <SimpleField type=\"int\"
> name=\"MaxTemp\"></SimpleField>";
> $kml_string = $kml_string . "  </Schema>";
> $kml_string = $kml_string . "  <NdfdData>";
> $kml_string = $kml_string . "    <name>Maximum Temperature</name>";
> $kml_string = $kml_string . "    <description>90F valid at
> 2007-06-26T00:00:00-04:00</description>";
> $kml_string = $kml_string . "    <Point>";
> $kml_string = $kml_string . "      <coordinates>-77.37,37.82</coordinates>";
> $kml_string = $kml_string . "    </Point>";
> $kml_string = $kml_string . "    <UOM>F</UOM>";
> $kml_string = $kml_string . "
> <ValidTime>2007-06-26T00:00:00-04:00</ValidTime>";
> $kml_string = $kml_string . "    <MaxTemp>95</MaxTemp>";
> $kml_string = $kml_string . "  </NdfdData>";
> $kml_string = $kml_string . "  <NdfdData>";
> $kml_string = $kml_string . "    <name>Maximum Temperature</name>";
> $kml_string = $kml_string . "    <description>89F valid at
> 2007-06-26T00:00:00-04:00</description>";
> $kml_string = $kml_string . "    <Point>";
> $kml_string = $kml_string . "      <coordinates>-77.5,38.00</coordinates>";
> $kml_string = $kml_string . "    </Point>";
> $kml_string = $kml_string . "    <UOM>F</UOM>";
> $kml_string = $kml_string . "
> <ValidTime>2007-06-26T00:00:00-04:00</ValidTime>";
> $kml_string = $kml_string . "    <MaxTemp>89</MaxTemp>";
> $kml_string = $kml_string . "  </NdfdData>";
> $kml_string = $kml_string . "</Document>";
> $kml_string = $kml_string . "</kml>";
>
> $descriptorAssignments = array(
>    0 => array("pipe", "r"),  // stdin is a pipe that the child will read
> from
>    1 => array("pipe", "w"),  // stdout is a pipe that the child will
> write to
>    2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file
> to write to
> );
>
> $kmz_process = proc_open('zip',$descriptorAssignments,$pipes);
>
> if (is_resource($kmz_process))
> {
>    fwrite($pipes[0],$kml_string);
>    fclose($pipes[0]);
>
>    $kmz_content = stream_get_contents($pipes[1]);
>
>    fclose($pipes[1]);
>
>    $return_value = proc_close($kmz_process);
>
>    //  Only outputting data to ensure it is a properly formatted zip file
>    //  Normally, a SOAP service will sent the data as a base64 encoded
> payload
>    $output_file = fopen('ndfdViaPipe.kmz','w');
>    fwrite($output_file,$kmz_content);
>    fclose($output_file);
> }
>
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Graham

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux