mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-30 12:52:08 +02:00
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@256372 c90b9560-bf6c-de11-be94-00142212c4b1
122 lines
3.3 KiB
XML
122 lines
3.3 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.1 $ -->
|
|
<!-- EN-Revision: 1.2 Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
|
|
<chapter xml:id="stream.examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemples avec <function>file_get_contents</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
/* Lit un fichier local dans le dossier /home/bar */
|
|
$localfile = file_get_contents("/home/bar/foo.txt");
|
|
|
|
/* Identique au précédent, mais utilise explicitement le gestionnaire FILE */
|
|
$localfile = file_get_contents("file:///home/bar/foo.txt");
|
|
|
|
/* Lit un fichier distant sur le serveur www.example.com avec le protocole HTTP */
|
|
$httpfile = file_get_contents("http://www.example.com/foo.txt");
|
|
|
|
/* Lit le même fichier sur le serveur www.example.com avec le protocole HTTPS */
|
|
$httpsfile = file_get_contents("https://www.example.com/foo.txt");
|
|
|
|
/* Lit un fichier distant sur le serveur ftp.example.com en utilisant le protocole FTP */
|
|
$ftpfile = file_get_contents("ftp://user:pass@ftp.example.com/foo.txt");
|
|
|
|
/* Lit un fichier distant sur le serveur ftp.example.com en utilisant le protocole FTPS */
|
|
$ftpsfile = file_get_contents("ftps://user:pass@ftp.example.com/foo.txt");
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Envoi d'une requête de type POST sur un serveur sécurisé</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
/* Envoi d'une requête POST sur le serveur https://secure.example.com/form_action.php
|
|
* Inclusion des variables "foo" et "bar"
|
|
*/
|
|
|
|
$sock = fsockopen("ssl://secure.example.com", 443, $errno, $errstr, 30);
|
|
if (!$sock) die("$errstr ($errno)\n");
|
|
|
|
$data = "foo=" . urlencode("Valeur de Foo") . "&bar=" . urlencode("Valeur de Bar");
|
|
|
|
fputs($sock, "POST /form_action.php HTTP/1.0\r\n");
|
|
fputs($sock, "Host: secure.example.com\r\n");
|
|
fputs($sock, "Content-type: application/x-www-form-urlencoded\r\n");
|
|
fputs($sock, "Content-length: " . strlen($data) . "\r\n");
|
|
fputs($sock, "Accept: */*\r\n");
|
|
fputs($sock, "\r\n");
|
|
fputs($sock, "$data\r\n");
|
|
fputs($sock, "\r\n");
|
|
|
|
$headers = "";
|
|
while ($str = trim(fgets($sock, 4096))) {
|
|
$headers .= "$str\n";
|
|
}
|
|
|
|
echo "\n";
|
|
|
|
$body = "";
|
|
while (!feof($sock)) {
|
|
$body .= fgets($sock, 4096);
|
|
}
|
|
|
|
fclose($sock);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Écrire des données dans un fichier compressé</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
/* Création d'un fichier compressé contenant une chaîne arbitraire
|
|
* Le fichier peut être lu en utilisant le gestionnaire compress.zlib
|
|
* ou simplement decompresse; en ligne de commande avec 'gzip -d foo-bar.txt.gz'
|
|
*/
|
|
$fp = fopen("compress.zlib://foo-bar.txt.gz","w");
|
|
if (!$fp) die("Impossible de créer le fichier.");
|
|
|
|
fwrite($fp, "Ceci est un test.\n");
|
|
|
|
fclose($fp);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</chapter>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|
|
|