cvs: phpdoc-it /reference/filesystem/functions fclose.xml feof.xml fflush.xml fgetc.xml fgetcsv.xml fgets.xml fgetss.xml file.xml fileatime.xml
fopen.xml

From: Date: Fri, 17 Oct 2003 19:53:34 +0000
Subject: cvs: phpdoc-it /reference/filesystem/functions fclose.xml feof.xml fflush.xml fgetc.xml fgetcsv.xml fgets.xml fgetss.xml file.xml fileatime.xml
fopen.xml
Groups: php.doc.it 
Request: Send a blank email to doc-it+get-467@lists.php.net to get a copy of this message
darvina Fri Oct 17 15:53:34 2003 EDT Modified files: /phpdoc-it/reference/filesystem/functions fclose.xml feof.xml fflush.xml fgetc.xml fgetcsv.xml fgets.xml fgetss.xml file.xml fileatime.xml fopen.xml Log: Sync to En tree

Index: phpdoc-it/reference/filesystem/functions/fclose.xml diff -u phpdoc-it/reference/filesystem/functions/fclose.xml:1.3 phpdoc-it/reference/filesystem/functions/fclose.xml:1.4 --- phpdoc-it/reference/filesystem/functions/fclose.xml:1.3 Wed May 29 06:13:44 2002 +++ phpdoc-it/reference/filesystem/functions/fclose.xml Fri Oct 17 15:53:34 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- EN-Revision: 1.2 Maintainer: spisto Status: ready --> +<!-- EN-Revision: 1.5 Maintainer: spisto Status: ready --> <!-- CREDITS: cortesi --> <!-- splitted from ./it/functions/filesystem.xml, last change in rev 1.15 --> <refentry id="function.fclose"> @@ -11,10 +11,10 @@ <title>Descrizione</title> <methodsynopsis> <type>bool</type><methodname>fclose</methodname> - <methodparam><type>int</type><parameter>fp</parameter></methodparam> + <methodparam><type>resource</type><parameter>handle</parameter></methodparam> </methodsynopsis> <para> - Chiude il file puntato da <parameter>fp</parameter>. + Chiude il file puntato da <parameter>handle</parameter>. </para> <para> &return.success; @@ -23,6 +23,22 @@ Il puntatore al file deve essere valido e deve puntare ad un file aperto correttamente da <function>fopen</function> o da <function>fsockopen</function>. + </para> + <para> + <example> + <title>Un semplice esempio di <function>fclose</function></title> + <programlisting role="php"> +<![CDATA[ +<?php + + $handle = fopen('somefile.txt', 'r'); + + fclose($handle); + +?> +]]> + </programlisting> + </example> </para> </refsect1> </refentry> Index: phpdoc-it/reference/filesystem/functions/feof.xml diff -u phpdoc-it/reference/filesystem/functions/feof.xml:1.2 phpdoc-it/reference/filesystem/functions/feof.xml:1.3 --- phpdoc-it/reference/filesystem/functions/feof.xml:1.2 Wed Apr 17 03:06:36 2002 +++ phpdoc-it/reference/filesystem/functions/feof.xml Fri Oct 17 15:53:34 2003 @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- splitted from ./it/functions/filesystem.xml, last change in rev 1.15 --> -<!-- last change to 'feof' in en/ tree in rev 1.2 --> -<!-- EN-Revision: 1.2 Maintainer: cortesi Status: working --> -<!-- OLD-Revision: 1.134/EN.1.2 --> +<!-- EN-Revision: 1.4 Maintainer: cortesi Status: working --> <refentry id="function.feof"> <refnamediv> <refname>feof</refname> @@ -11,8 +8,8 @@ <refsect1> <title>Descrizione</title> <methodsynopsis> - <type>int</type><methodname>feof</methodname> - <methodparam><type>int</type><parameter>fp</parameter></methodparam> + <type>bool</type><methodname>feof</methodname> + <methodparam><type>resource</type><parameter>handle</parameter></methodparam> </methodsynopsis> <para> Restituisce &true; se il puntatore al file ha raggiunto la fine del file (EOF) Index: phpdoc-it/reference/filesystem/functions/fflush.xml diff -u phpdoc-it/reference/filesystem/functions/fflush.xml:1.2 phpdoc-it/reference/filesystem/functions/fflush.xml:1.3 --- phpdoc-it/reference/filesystem/functions/fflush.xml:1.2 Wed Apr 17 03:06:36 2002 +++ phpdoc-it/reference/filesystem/functions/fflush.xml Fri Oct 17 15:53:34 2003 @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- splitted from ./it/functions/filesystem.xml, last change in rev 1.15 --> -<!-- last change to 'fflush' in en/ tree in rev 1.43 --> -<!-- EN-Revision: 1.2 Maintainer: cortesi Status: working --> -<!-- OLD-Revision: 1.134/EN.1.43 --> +<!-- EN-Revision: 1.5 Maintainer: cortesi Status: working --> <refentry id="function.fflush"> <refnamediv> <refname>fflush</refname> @@ -11,12 +8,12 @@ <refsect1> <title>Descrizione</title> <methodsynopsis> - <type>int</type><methodname>fflush</methodname> - <methodparam><type>int</type><parameter>fp</parameter></methodparam> + <type>bool</type><methodname>fflush</methodname> + <methodparam><type>resource</type><parameter>handle</parameter></methodparam> </methodsynopsis> <para> Questa funzione forza la scrittura di tutto l'output bufferizzato sulla - risorsa puntata da puntatore <parameter>fp</parameter>. + risorsa puntata dal puntatore <parameter>handle</parameter>. Restituisce &true; se ha successo, &false; altrimenti. </para> Index: phpdoc-it/reference/filesystem/functions/fgetc.xml diff -u phpdoc-it/reference/filesystem/functions/fgetc.xml:1.2 phpdoc-it/reference/filesystem/functions/fgetc.xml:1.3 --- phpdoc-it/reference/filesystem/functions/fgetc.xml:1.2 Wed Apr 17 03:06:36 2002 +++ phpdoc-it/reference/filesystem/functions/fgetc.xml Fri Oct 17 15:53:34 2003 @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- splitted from ./it/functions/filesystem.xml, last change in rev 1.15 --> -<!-- last change to 'fgetc' in en/ tree in rev 1.2 --> -<!-- EN-Revision: 1.2 Maintainer: cortesi Status: working --> -<!-- OLD-Revision: 1.134/EN.1.2 --> +<!-- EN-Revision: 1.9 Maintainer: cortesi Status: working --> <refentry id="function.fgetc"> <refnamediv> <refname>fgetc</refname> @@ -10,19 +7,44 @@ </refnamediv> <refsect1> <title>Descrizione</title> - <methodsynopsis> - <type>string</type><methodname>fgetc</methodname> - <methodparam><type>int</type><parameter>fp</parameter></methodparam> - </methodsynopsis> + <methodsynopsis> + <type>string</type><methodname>fgetc</methodname> + <methodparam><type>resource</type><parameter>handle</parameter></methodparam> + </methodsynopsis> <para> Restituisce una stringa contenente un singolo carattere letto dal file puntato - da fp. Restituisce &false; alla fine del file (EOF). + da <parameter>handle</parameter>. + Restituisce &false; alla fine del file (EOF). </para> <para> Il puntatore al file deve essere valido e deve puntare ad un file correttamente aperto da <function>fopen</function>, <function>popen</function> o <function>fsockopen</function>. </para> + + &return.falseproblem; + + <para> + <example> + <title>Un esempio per <function>fgetc</function></title> + <programlisting role="php"> +<![CDATA[ +<?php +$fp = fopen('somefile.txt', 'r'); +if (!$fp) { + echo 'Non si riesce ad aprire il file somefile.txt'; +} +while (false !== ($char = fgetc($fp))) { + echo "$char\n"; +} +?> +]]> + </programlisting> + </example> + </para> + + &note.bin-safe; + <para> Vedere anche <function>fread</function>, <function>fopen</function>, <function>popen</function>, <function>fsockopen</function> e Index: phpdoc-it/reference/filesystem/functions/fgetcsv.xml diff -u phpdoc-it/reference/filesystem/functions/fgetcsv.xml:1.3 phpdoc-it/reference/filesystem/functions/fgetcsv.xml:1.4 --- phpdoc-it/reference/filesystem/functions/fgetcsv.xml:1.3 Tue Apr 23 06:35:18 2002 +++ phpdoc-it/reference/filesystem/functions/fgetcsv.xml Fri Oct 17 15:53:34 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- EN-Revision: 1.3 Maintainer: cortesi Status: working --> +<!-- EN-Revision: 1.8 Maintainer: cortesi Status: working --> <!-- splitted from ./it/functions/filesystem.xml, last change in rev 1.15 --> <refentry id="function.fgetcsv"> <refnamediv> @@ -10,24 +10,35 @@ <title>Descrizione</title> <methodsynopsis> <type>array</type><methodname>fgetcsv</methodname> - <methodparam><type>int</type><parameter>fp</parameter></methodparam> + <methodparam><type>resource</type><parameter>handle</parameter></methodparam> <methodparam><type>int</type><parameter>lunghezza</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>delimitatore</parameter></methodparam> + <methodparam choice="opt"><type>string</type><parameter>enclosure</parameter></methodparam> </methodsynopsis> <simpara> Simile a <function>fgets</function> eccetto per il fatto che <function>fgetcsv</function> analizza le righe lette alla ricerca di campi in in formato <acronym>CSV</acronym> e restituisce un vettore contenente i campi letti. Il delimitatore di campo è una virgola, a meno che non - venga specificato un altro delimitatore usando il terzo parametro opzionale. + venga specificato un altro delimitatore usando il terzo parametro opzionale, + mentre per il quarto parametro opzionale, <parameter>enclosure</parameter>, + il default sono i doppi apici. Entrambi i parametri, <parameter>delimitatore</parameter> + ed <parameter>enclosure</parameter>, hanno la dimensione di un carattere. + Se si forniscono stringhe di più di un carattere, verrà considerato solo il primo. </simpara> + <note> + <simpara> + Il parametro <parameter>enclosure</parameter> è stato aggiunto + in PHP 4.3.0. + </simpara> + </note> <simpara> - <parameter>fp</parameter> deve essere un puntatore valido ad un file + <parameter>Handle</parameter> deve essere un puntatore valido ad un file correttamente aperto da <function>fopen</function>, <function>popen</function> o <function>fsockopen</function>. </simpara> <simpara> - <parameter>lunghezza</parameter> deve essere maggiore della linea + <parameter>Lunghezza</parameter> deve essere maggiore della linea più lunga trovata nel file CSV (compresi i caratteri di fine riga). </simpara> <simpara> @@ -37,31 +48,36 @@ <note> <simpara> Una riga vuota in un file CVS verrà riportata come un vettore - contenente un solo campo vuoto (&null;) e non verrà trattata come un + contenente un solo campo vuoto (<type>null</type>) e non verrà trattata come un errore. </simpara> </note> - <example> - <title> - Esempio di <function>fgetcsv</function> - Legge e scrive l'intero contenuto - di un file CSV. - </title> - <programlisting role="php"> + <para> + <example> + <title>Legge e scrive l'intero contenuto di un file CSV.</title> + <programlisting role="php"> <![CDATA[ +<?php $row = 1; -$fp = fopen ("test.csv","r"); -while ($data = fgetcsv ($fp, 1000, ",")) { +$handle = fopen ("test.csv","r"); +while ($data = fgetcsv ($handle, 1000, ",")) { $num = count ($data); - print "<p> $num campi sulla linea $row: <br>"; + print "<p> $num campi sulla linea $row: <br>\n"; $row++; for ($c=0; $c < $num; $c++) { - print $data[$c] . "<br>"; + print $data[$c] . "<br>\n"; } } -fclose ($fp); +fclose ($handle); +?> ]]> - </programlisting> - </example> + </programlisting> + </example> + </para> + <para> + Vedere anche <function>explode</function>, <function>file</function> e + <function>pack</function>. + </para> </refsect1> </refentry> Index: phpdoc-it/reference/filesystem/functions/fgets.xml diff -u phpdoc-it/reference/filesystem/functions/fgets.xml:1.2 phpdoc-it/reference/filesystem/functions/fgets.xml:1.3 --- phpdoc-it/reference/filesystem/functions/fgets.xml:1.2 Wed Apr 17 03:06:36 2002 +++ phpdoc-it/reference/filesystem/functions/fgets.xml Fri Oct 17 15:53:34 2003 @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- splitted from ./it/functions/filesystem.xml, last change in rev 1.15 --> -<!-- last change to 'fgets' in en/ tree in rev 1.2 --> -<!-- EN-Revision: 1.2 Maintainer: cortesi Status: working --> -<!-- OLD-Revision: 1.134/EN.1.2 --> +<!-- EN-Revision: 1.9 Maintainer: cortesi Status: ready --> <refentry id="function.fgets"> <refnamediv> <refname>fgets</refname> @@ -12,18 +9,18 @@ <title>Descrizione</title> <methodsynopsis> <type>string</type><methodname>fgets</methodname> - <methodparam><type>int</type><parameter>fp</parameter></methodparam> + <methodparam><type>resource</type><parameter>handle</parameter></methodparam> <methodparam><type>int</type><parameter>length</parameter></methodparam> </methodsynopsis> <para> - Restituisce una stringa di length - 1 byte letti dal file puntato da fp. - La lettura termina quando sono stati letti length - 1 byte, in un caratere - i newline (che viene incluso nel valore restituito), o alla fine del file - (EOF) qualora giunga prima. Se no length is specified, the length - defaults to 1k, or 1024 bytes. + Restituisce una stringa di length - 1 byte letti dal file puntato da <parameter>handle</parameter>. + La lettura termina quando sono stati letti length - 1 byte, oppure si incontra il carattere + di newline (che viene incluso nel valore restituito), oppure alla fine del file + (EOF) qualora giunga prima. Se non si specifica length, si assume + come default 1k, o 1024 byte. </para> <para> - Se si verifica un errore, restituisce &false;. + Se si verifica un errore, la funzione restituisce &false;. </para> <para> Errori comuni: @@ -44,24 +41,42 @@ <title>Legge un file riga per riga</title> <programlisting role="php"> <![CDATA[ -$fd = fopen ("/tmp/inputfile.txt", "r"); -while (!feof ($fd)) { +<?php +$handle = fopen ("/tmp/inputfile.txt", "r"); +while (!feof ($handle)) { $buffer = fgets($fd, 4096); echo $buffer; } -fclose ($fd); +fclose ($handle); +?> ]]> </programlisting> </example> </para> <note> <simpara> - The <parameter>length</parameter> parameter became optional in PHP 4.2.0 + Il parametro <parameter>length</parameter> è diventato opzionale a partire da PHP + 4.2.0, se omesso, si assume come lunghezza della linea 1024. + A partire dalla versione 4.3, l'omissione del parametro <parameter>length</parameter> + comporta la lettura del flusso d'ingresso sino al raggiungimento della fine della linea. + Se la maggior parte delle righe lette dal file hanno dimensione superiore a 8KB, + è più efficiente specificare la lunghezza massima + della linea. </simpara> </note> + <note> + <simpara> + A partire da PHP 4.3 questa funzione è 'binary safe'. Le versioni + precedenti non lo sono. + </simpara> + </note> + &note.line-endings; <para> - Vedere anche <function>fread</function>, <function>fopen</function>, - <function>popen</function>, <function>fgetc</function>, + Vedere anche <function>fread</function>, + <function>fgetc</function>, + <function>stream_get_line</function>, + <function>fopen</function>, + <function>popen</function>, <function>fsockopen</function> e <function>socket_set_timeout</function>. </para> Index: phpdoc-it/reference/filesystem/functions/fgetss.xml diff -u phpdoc-it/reference/filesystem/functions/fgetss.xml:1.2 phpdoc-it/reference/filesystem/functions/fgetss.xml:1.3 --- phpdoc-it/reference/filesystem/functions/fgetss.xml:1.2 Wed Apr 17 03:06:36 2002 +++ phpdoc-it/reference/filesystem/functions/fgetss.xml Fri Oct 17 15:53:34 2003 @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- splitted from ./it/functions/filesystem.xml, last change in rev 1.15 --> -<!-- last change to 'fgetss' in en/ tree in rev 1.2 --> -<!-- EN-Revision: 1.2 Maintainer: cortesi Status: working --> -<!-- OLD-Revision: 1.134/EN.1.2 --> +<!-- EN-Revision: 1.5 Maintainer: cortesi Status: working --> <refentry id="function.fgetss"> <refnamediv> <refname>fgetss</refname> @@ -12,7 +9,7 @@ <title>Descrizione</title> <methodsynopsis> <type>string</type><methodname>fgetss</methodname> - <methodparam><type>int</type><parameter>fp</parameter></methodparam> + <methodparam><type>resource</type><parameter>handle</parameter></methodparam> <methodparam><type>int</type><parameter>length</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>allowable_tags</parameter></methodparam> </methodsynopsis> @@ -31,6 +28,7 @@ </para> </note> </para> + &note.line-endings; <para> Vedere anche <function>fgets</function>, <function>fopen</function>, <function>fsockopen</function>, <function>popen</function> e Index: phpdoc-it/reference/filesystem/functions/file.xml diff -u phpdoc-it/reference/filesystem/functions/file.xml:1.2 phpdoc-it/reference/filesystem/functions/file.xml:1.3 --- phpdoc-it/reference/filesystem/functions/file.xml:1.2 Wed Apr 17 03:06:37 2002 +++ phpdoc-it/reference/filesystem/functions/file.xml Fri Oct 17 15:53:34 2003 @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- splitted from ./it/functions/filesystem.xml, last change in rev 1.15 --> -<!-- last change to 'file' in en/ tree in rev 1.2 --> -<!-- EN-Revision: 1.2 Maintainer: cortesi Status: working --> -<!-- OLD-Revision: 1.134/EN.1.2 --> +<!-- EN-Revision: 1.10 Maintainer: cortesi Status: working --> <refentry id="function.file"> <refnamediv> <refname>file</refname> @@ -14,23 +11,18 @@ <type>array</type><methodname>file</methodname> <methodparam><type>string</type><parameter>filename</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>use_include_path</parameter></methodparam> + <methodparam choice="opt"><type>resource</type><parameter>context</parameter></methodparam> </methodsynopsis> <para> Identica a <function>readfile</function>, eccetto per il fatto che <function>file</function> restituisce il file in un vettore. Ogni elemento del vettore corrisponde ad una riga del file, con il carattere di - newline ancora inserito. + newline ancora inserito. Se la funzione non riesce restituisce + &false;. </para> - <note> - <para> - Each line in the resulting array will include the line ending, so you - still need to use <function>trim</function> if you do not want the line - ending present. - </para> - </note> <para> - Puoi impostare il secondo parametro (opzionale) ad "1", se - vuoi cercare il file nel <link + Puoi impostare il secondo parametro, <parameter>use_include_path</parameter>, (opzionale) ad "1", + se vuoi cercare il file nel <link linkend="ini.include-path">include_path</link>. </para> <para> @@ -38,31 +30,46 @@ <programlisting role="php"> <![CDATA[ <?php -// inserisce una pagina web in un array e la stampa -$fcontents = file ('http://www.php.net'); -while (list ($line_num, $line) = each ($fcontents)) { - echo "&lt;b&gt;Line $line_num:&lt;/b&gt; " . htmlspecialchars ($line) . "&lt;br&gt;\n"; +// inserisce una pagina web in un array e la stampa. In questo eesempio useremo il protocollo +// HTTP per otterenere il sorgente di un URL +$lines = file ('http://www.example.com/'); +// Ciclo atrraverso l'array, si visualizzerà il sorgente come html ed i numeri di linea +foreach ($lines as $line_num => $line) { + echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n"; } -// inserisce una pagina web in una stringa -$fcontents = join ('', file ('http://www.php.net')); +// Un'altro esempio, inserisce la pagina web in una stringa. Vedere anche file_get_contents(). +$html = implode ('', file ('http://www.example.com/')); ?> ]]> </programlisting> </informalexample> </para> +&tip.fopen-wrapper; + <note> + <para> + Ciascuna riga dell'array restituito conterrà il carattere di fine riga, occorre, pertanto, + utilizzare <function>trim</function> se si desidera rimuovere il carattere + di fine riga. + </para> + </note> + &note.line-endings; <note> <para> - As of PHP 4.3.0 you can use <function>file_get_contents</function> to - return the contents of a file as a string in a binary safe manner. + A partire da PHP 4.3.0 si può utilizzare <function>file_get_contents</function> per + memorizzare il contenuto di un file in una stringa in formato binario. </para> </note> - &note.not-bin-safe; - &tip.fopen-wrapper; + <note> + <simpara> + Il supporto al contesto è stato aggiunto nel <literal>PHP 5.0.0</literal> + </simpara> + </note> <para> Vedere anche <function>readfile</function>, - <function>fopen</function>, <function>fsockopen</function> e - <function>popen</function>. + <function>fopen</function>, <function>fsockopen</function>, + <function>popen</function>, <function>file_get_contents</function> e + <function>include</function>. </para> </refsect1> </refentry> Index: phpdoc-it/reference/filesystem/functions/fileatime.xml diff -u phpdoc-it/reference/filesystem/functions/fileatime.xml:1.2 phpdoc-it/reference/filesystem/functions/fileatime.xml:1.3 --- phpdoc-it/reference/filesystem/functions/fileatime.xml:1.2 Wed Apr 17 03:06:37 2002 +++ phpdoc-it/reference/filesystem/functions/fileatime.xml Fri Oct 17 15:53:34 2003 @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- splitted from ./it/functions/filesystem.xml, last change in rev 1.15 --> -<!-- last change to 'fileatime' in en/ tree in rev 1.2 --> -<!-- EN-Revision: 1.2 Maintainer: cortesi Status: working --> -<!-- OLD-Revision: 1.134/EN.1.2 --> +<!-- EN-Revision: 1.4 Maintainer: cortesi Status: working --> <refentry id="function.fileatime"> <refnamediv> <refname>fileatime</refname> @@ -19,10 +16,6 @@ in caso di errore. L'ora viene restituita come un timestamp Unix. </simpara> <simpara> - I risultati di questa funzione vengono memorizzati nella cache. Vedi - <function>clearstatcache</function> per maggiori informazioni. - </simpara> - <simpara> N.B.: Si suppone che l'atime di un file cambi ogni volta che i blocchi di dati del file vengono letti. Ciò può risultare costoso per le performance quando una applicazione accede con regolarità @@ -32,10 +25,33 @@ costituiscono un esempo frequente. In tali filesystem queste funzioni sono inutili. </simpara> + &note.clearstatcache; + + &note.no-remote; + + <para> + <example> + <title>Esempio per <function>fileatime</function></title> + <programlisting role="php"> +<![CDATA[ +<?php + +// visualizza, ad esempio, che somefile.txt è stato aperto il: December 29 2002 22:16:23. + +$filename = 'somefile.txt'; +if (file_exists($filename)) { + echo "$filename è stato aperto il: " . date ("F d Y H:i:s.", fileatime($filename)); +} + +?> +]]> + </programlisting> + </example> + </para> <simpara> - Questa funzione non lavora con i <link - linkend="features.remote-files">file remoti</link>; i file da - esaminare devono essere accessibili attraverso il filesystem del server. + Vedere anche <function>filemtime</function>, + <function>fileinode</function> e + <function>date</function>. </simpara> </refsect1> </refentry> Index: phpdoc-it/reference/filesystem/functions/fopen.xml diff -u phpdoc-it/reference/filesystem/functions/fopen.xml:1.3 phpdoc-it/reference/filesystem/functions/fopen.xml:1.4 --- phpdoc-it/reference/filesystem/functions/fopen.xml:1.3 Tue Apr 23 06:18:28 2002 +++ phpdoc-it/reference/filesystem/functions/fopen.xml Fri Oct 17 15:53:34 2003 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- EN-Revision: 1.2 Maintainer: cortesi Status: working --> -<!-- splitted from ./it/functions/filesystem.xml, last change in rev 1.15 --> +<!-- EN-Revision: 1.18 Maintainer: cortesi Status: working --> +<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.fopen"> <refnamediv> <refname>fopen</refname> @@ -9,155 +9,258 @@ <refsect1> <title>Descrizione</title> <methodsynopsis> - <type>int</type><methodname>fopen</methodname> + <type>resource</type><methodname>fopen</methodname> <methodparam><type>string</type><parameter>filename</parameter></methodparam> <methodparam><type>string</type><parameter>mode</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>use_include_path</parameter></methodparam> + <methodparam choice="opt"><type>resource</type><parameter>zcontext</parameter></methodparam> </methodsynopsis> <simpara> - Se <parameter>filename</parameter> inizia con "http://" (indipendentemente - dalle maiuscole), viene aperta una connessione HTTP 1.0 al server - specificato, la pagina viene richiesta usando il metodo HTTP - GET e un puntatore a file viene restituito all'inizio del corpo della - risposta. Un header 'Host:' viene inviato con la richiesta - in modo di soddisfare i virtual host name-based. + La funzione <function>fopen</function> apre un collegamneto tra una risorsa, indicata + dal parametro <parameter>filename</parameter>, ed un flusso. Se il parametro + <parameter>filename</parameter> è del tipo "scheme://...", + si assume essere un URL ed il PHP cercherà il modulo di gestione del protocollo + (detto anche wrapper) per quello schema. Se non vi sono wrapper + registrati per il protocollo richiesto, il PHP genererà un + messaggio per aiutare a trovare potenziali problemi nello script + e quindi procede considerando <parameter>filename</parameter> + come un file regolare. </simpara> <simpara> - As of PHP 4.3.0 (not yet released), if you have compiled in - support for OpenSSL, you may use "https://" to open an HTTP - connection over SSL. + Se il PHP ha stabilito che <parameter>filename</parameter> indica un file + locale, tenterà di aprire detto file come stream. + Il file in oggetto dovrà esere accessibile dal PHP, occorre, pertanto, assicurasi che + i permessi di accesso del file lo consentano. + Se si è attivato il &safemode;, + oppure <link linkend="ini.open-basedir">open_basedir</link> si avranno + ulteriori restrizioni. </simpara> <simpara> - Nota che il puntatore al file ti permette di ottenere solo il - <emphasis>body</emphasis> della risposta; to retrieve the HTTP - response header you need to be using PHP 4.0.5 or later; - The headers will be stored in the $http_response_header variable. - As of PHP 4.3.0 (not yet released), the header information can - be retrieved using the <function>fgetwrapperdata</function>. - </simpara> - <simpara> - HTTP connections are read-only; you cannot write data or copy - files to an HTTP resource. - </simpara> - <simpara> - Le versioni precedenti al PHP 4.0.5 non elaborano i redirect HTTP. Perciò, - le directory devono includere gli slash finali. - </simpara> - <simpara> - Se <parameter>filename</parameter> inizia con "ftp://" (case insensitive), - Viene aperta una connessione ftp al server specificato e viene restituito - un puntatore al file richiesto. Se il server non supporta l'FTP passivo, fallirà. - Via ftp puoi aprire - file sia in lettura che scrittura (ma non - contemporaneamente). - </simpara> - <simpara> - If <parameter>filename</parameter> is one of "php://stdin", - "php://stdout", or "php://stderr", the corresponding stdio - stream will be opened. (This was introduced in PHP 3.0.13; - in earlier versions, a filename such as "/dev/stdin" or - "/dev/fd/0" must be used to access the stdio streams.) - </simpara> - <simpara> - If <parameter>filename</parameter> begins with anything else, the - file will be opened from the filesystem, and a file pointer to - the file opened is returned. - </simpara> - <simpara> - If the open fails, the function returns &false;. + Se il PHP ha stabilito che <parameter>filename</parameter> indica un + protocollo registrato, e che tale protocollo è registrato come un URL + di rete, il PHP verificherà che + <link linkend="ini.allow-url-fopen">allow_url_fopen</link> + sia abilitato.Se fosse disabilitato, il PHP genererà un 'notice' e + la funzione fallirà. </simpara> + <note> + <simpara> + L'elenco dei protocolli supportati si trova in <xref linkend="wrappers"/>. + Alcuni protocolli (indicati anche come <literal>wrappers</literal>) supportano + il <literal>context</literal> e/o le opzioni del &php.ini; + Fare riferimento alle pagine specifiche del protocollo per avere l'elenco delle opzioni + che possono essere utilizzate. (Ad esempio il parametro del &php.ini; + <literal>user_agent</literal> è utilizzato dal wrapper <literal>http</literal>) + Per una descrizione del <literal>contexts</literal> e del + <parameter>zcontext</parameter>, fare riferimento a <xref linkend="ref.stream"/>. + </simpara> + </note> <para> - <parameter>mode</parameter> può essere uno dei seguenti: - <itemizedlist> - <listitem> - <simpara> - 'r' - Apre in sola lettura; posiziona il puntatore - all'inizio del file. - </simpara> - </listitem> - <listitem> - <simpara> - 'r+' - Apre in lettura e scrittura; posiziona il puntatore - all'inizio del file. - </simpara> - </listitem> - <listitem> - <simpara> - 'w' - Apre il file in sola scrittura; posiziona il puntatore all'inizio del file - e tronce il file alla lunghezza zero. - Se il file non esiste, tenta di crearlo. - </simpara> - </listitem> - <listitem> - <simpara> - 'w+' - Apre in lettura e scrittura; posiziona il puntatore all'inizio del file - e tronce il file alla lunghezza zero. - Se il file non esiste, tenta di crearlo. - </simpara> - </listitem> - <listitem> - <simpara> - 'a' - Apre in sola scrittura; posiziona il puntatore alla fine - del file. Se il file non esiste, tenta di - crearlo. - </simpara> - </listitem> - <listitem> - <simpara> - 'a+' - Apre in lettura e scrittura; posiziona il - puntatore alla fine del file. Se il file non esiste, tenta - di crearlo. - </simpara> - </listitem> - </itemizedlist> + Il parametro <parameter>mode</parameter> indica il tipo di accesso + richiesto per il flusso. Esso può essere: + <table> + <title> + Elenco dei possibili valori usati da <function>fopen</function> + per il parametro <parameter>mode</parameter> + </title> + <tgroup cols="2"> + <thead> + <row> + <entry><parameter>mode</parameter></entry> + <entry>Descrizione</entry> + </row> + </thead> + <tbody> + <row> + <entry><literal>'r'</literal></entry> + <entry> + Apre in sola lettura; posiziona il puntatore + all'inizio del file. + </entry> + </row> + <row> + <entry><literal>'r+'</literal></entry> + <entry> + Apre in lettura e scrittura; posiziona il puntatore + all'inizio del file. + </entry> + </row> + <row> + <entry><literal>'w'</literal></entry> + <entry> + Apre il file in sola scrittura; posiziona il puntatore all'inizio del file + e tronca il file alla lunghezza zero. + Se il file non esiste, tenta di crearlo. + </entry> + </row> + <row> + <entry><literal>'w+'</literal></entry> + <entry> + Apre in lettura e scrittura; posiziona il puntatore all'inizio del file + e tronce il file alla lunghezza zero. + Se il file non esiste, tenta di crearlo. + </entry> + </row> + <row> + <entry><literal>'a'</literal></entry> + <entry> + Apre in sola scrittura; posiziona il puntatore alla fine + del file. Se il file non esiste, tenta di crearlo. + </entry> + </row> + <row> + <entry><literal>'a+'</literal></entry> + <entry> + Apre in lettura e scrittura; posiziona il + puntatore alla fine del file. Se il file non esiste, tenta + di crearlo. + </entry> + </row> + <row> + <entry><literal>'x'</literal></entry> + <entry> + Crea ed apre il file in sola scrittura; posiziona il puntatore all'inizio + del file. Se il file esiste già la chiamata a + <function>fopen</function> fallirà restituendo &false; e verrà generato + un errore di lievllo <constant>E_WARNING</constant>. Se il file + non esiste si tenterà di crearlo. Questo equivale a + specificare i flag <literal>O_EXCL|O_CREAT</literal> nella + sottostante chiamata a <literal>open(2)</literal> . Questa opzione è + supportata a partire dalla versione 4.3.2 di PHP, e funziona solo con i file locali. + </entry> + </row> + <row> + <entry><literal>'x+'</literal></entry> + <entry> + Crea ed apre il file in lettura e scrittura; posiziona il puntatore all'inizio + del file. Se il file esiste già la chiamata a + <function>fopen</function> fallirà restituendo &false; e verrà generato + un errore di lievllo <constant>E_WARNING</constant>. Se il file + non esiste si tenterà di crearlo. Questo equivale a + specificare i flag <literal>O_EXCL|O_CREAT</literal> nella + sottostante chiamata a <literal>open(2)</literal> . Questa opzione è + supportata a partire dalla versione 4.3.2 di PHP, e funziona solo con i file locali. + </entry> + </row> + </tbody> + </tgroup> + </table> </para> <note> <para> - <parameter>mode</parameter> può anche essere impostato a - 'b'. Ciò è utile solo in sistemi che differenziano fra file binari e di testo - (ad esempio Windows. è inutile su Unix). - Se non è necessario, tale valore verrà ignorato. + Differenti famiglie di file system hanno differenti tipi di terminatori + di riga. Quando si scrive un file di testo e si desidera inserire una interruzione + di linea, occorre utilizzare il terminatore appropriato per il sistema operativo + utilizzato. I sistemi basati su Unix utilizzano <literal>\n</literal> come + terminatore di riga, i sistemi basati su Windows utilizzano <literal>\r\n</literal> + mentre i sistemi Macintosh utilizzano + <literal>\r</literal>. + </para> + <para> + Se si utilizza un errato terminatore di riga quando si scrivono i file, + si può verificare che altre applicazioni accedendo a questi file abbiano + comportamenti bizzarri. + </para> + <para> + Windows ha un flag di traduzione della modalità testo (<literal>'t'</literal>) + che in modo trasparente converte <literal>\n</literal> in + <literal>\r\n</literal> mentre si lavora sul file. Ovviamente si ha anche + il flag <literal>'b'</literal> per forzare una modalità binaria, nella quale non + si ha la conversione dei dati. Se si usano questi flag, + <literal>'b'</literal> oppure <literal>'t'</literal>, devono essere posizionati + come ultimo carattere del parametro <parameter>mode</parameter>. + </para> + <para> + La modalità di conversione di default dipende dalla SAPI e dalla versione + di PHP che si sta utlizzando, pertanto si incoraggia l'uso dei flag appropriati per + aumentare la portabilità degli script. Si dovrebbe utilizzare <literal>'t'</literal> + se si lavora con dei file di testo, e si utilizza + <literal>\n</literal> per indicare il fine linea, e ci si aspetta che + che altre applicazioni, tipo notepad, leggano il file prodotto. In tutti + gli altri casi si dovrebbe utilizzare <literal>'b'</literal> + </para> + <para> + Se non si specifica il flag 'b' quando si lavora con file binari, si + possono avere situazioni anomale nei dati, tipo immagini corrotte, + e situazioni anomale con i caratteri <literal>\r\n</literal>. + </para> + <para> + <emphasis>Per motivi di portabilità è fortemente raccomandato l'uso + del flag 'b' quando si aprono dei file con <function>fopen</function>. + </emphasis> + </para> + <para> + <emphasis>Inoltre, sempre per la portabilità, è anche fortemente raccomandato + di aggiornare il codice che utilizza o che confida nel modalità + <literal>'t'</literal> in modo da utilizzare il corretto terminatore di linea. + </emphasis> + </para> + <para> + <emphasis>A partire dal PHP 4.3.2, per tutte le piattaforme che distinguono tra + tra testo e binario, la modalità di default è la binaria. Se si hanno problemi + negli script dopo l'aggiornamneto, tentare l'utilizzo del flag + <literal>'t'</literal> per tamponare i problemi fino a quando non si + sono resi gli script più portabili come descritto in precedenza. + </emphasis> </para> </note> <para> - Puoi utilizzare il terzo parametro opzionale ed impostarlo ad "1", se - vuoi cercare il file anche - nel <link linkend="ini.include-path">include_path</link>. + Il terzo parametro opzionale <parameter>use_include_path</parameter> + può essere impostato a '1' oppure a &true; se si desidera cercare il file in + <link linkend="ini.include-path">include_path</link>. </para> + <simpara> + Se la open fallisce, la funzione restituisce &false; e viene generato un errore + di tipo <constant>E_WARNING</constant>. Si può utilizzare + <link linkend="language.operators.errorcontrol">@</link> + per sopprimere questo warning. + </simpara> <para> <example> - <title>Esempio di <function>fopen</function></title> + <title>Esempi di <function>fopen</function></title> <programlisting role="php"> <![CDATA[ -$fp = fopen ("/home/rasmus/file.txt", "r"); -$fp = fopen ("/home/rasmus/file.gif", "wb"); -$fp = fopen ("http://www.example.com/", "r"); -$fp = fopen ("ftp://user:password@example.com/", "w"); +<?php +$handle = fopen ("/home/rasmus/file.txt", "r"); +$handle = fopen ("/home/rasmus/file.gif", "wb"); +$handle = fopen ("http://www.example.com/", "r"); +$handle = fopen ("ftp://user:password@example.com/somefile.txt", "w"); +?> ]]> </programlisting> </example> </para> <simpara> - Se incontri problemi nella lettura o scrittura di file e stai usando una - versione di PHP come modulo server, ricorda - di verificare che i file e le directory che stai usando siano - accessibili al processo server. + Se si dovessero manifestare dei problemi nella lettura o scrittura + di file e si sta utilizzando la versione server di PHP, occorre verificare + che i file e le directory utilizzate dallo script + siano accessibili dal processo del server. </simpara> <para> - Sulle piattaforme Windows, fai attenzione ad dichiarare ogni backslash - utilizzata nel percorso del file, o utilizza gli slash semplici. + Sulla piattaforma Windows occorre prestare attenzione ai backslash + nei percorsi dei file; questi devono essere preceduti dal caratteri di escape '\', oppure utilizzare + lo slash '/'. <informalexample> <programlisting role="php"> <![CDATA[ -$fp = fopen ("c:\\data\\info.txt", "r"); +<?php +$handle = fopen ("c:\\data\\info.txt", "r"); +?> ]]> </programlisting> </informalexample> </para> <simpara> - Vedere anche <function>fclose</function>, + Vedere anche <xref linkend="wrappers"/>, + <function>fclose</function>, + <function>fgets</function>, + <function>fread</function>, + <function>fwrite</function>, <function>fsockopen</function>, - <function>socket_set_timeout</function> e + <function>file</function>, + <function>file_exists</function>, + <function>is_readable</function>, + <function>stream_set_timeout</function> e <function>popen</function>. </simpara> </refsect1>
« previous php.doc.it (#467) next »