PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Creating a File in Memory
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Creating a File in Memory

Réponse
 
LinkBack Outils de la discussion
Vieux 07/09/2007, 20h49   #1
John Schattel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Creating a File in Memory

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 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);
}

?>
  Réponse avec citation
Vieux 07/09/2007, 22h07   #2
Graham Cossey
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Creating a File in Memory

Can't 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@noaa.gov> 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 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
  Réponse avec citation
Vieux 07/09/2007, 22h16   #3
Michael Preslar
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Creating a File in Memory

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

$kml_string = <<<STOP
all of
the soap
maybe some water
some chips if you have them
STOP

On 9/7/07, John Schattel <John.Schattel@noaa.gov> 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 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
>
>

  Réponse avec citation
Vieux 08/09/2007, 16h10   #4
Per Jessen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Creating a File in Memory

John Schattel wrote:

> 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?


Add some headers before you send the file:

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"blah.zip\"");


/Per Jessen, Zürich
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h19.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15756 seconds with 12 queries