<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/features.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'features.remote-files.php',
    1 => 'Utilizzo di file remoti',
    2 => 'Utilizzo di file remoti',
  ),
  'up' => 
  array (
    0 => 'features.php',
    1 => 'Caratteristiche',
  ),
  'prev' => 
  array (
    0 => 'features.file-upload.errors.seealso.php',
    1 => 'Vedere anche:',
  ),
  'next' => 
  array (
    0 => 'features.connection-handling.php',
    1 => 'Gestione della connessione',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    'path' => 'features/remote-files.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="features.remote-files" class="chapter">
  <h1 class="title">Utilizzo di file remoti</h1>


  <p class="para">
   Se <code class="parameter">allow_url_fopen</code> è abilitato in 
   <var class="filename">php.ini</var>, si possono usare le URL <abbr title="Hypertext Transfer Protocol">HTTP</abbr> e <abbr title="File Transfer Protocol">FTP</abbr> 
   con la maggior parte delle funzioni che 
   richiedono nomi di file come parametri. Ioltre, le URL possono essere
   usate con i comandi <span class="function"><a href="function.include.php" class="function">include</a></span>,
   <span class="function"><a href="function.include-once.php" class="function">include_once</a></span>, <span class="function"><a href="function.require.php" class="function">require</a></span>e 
   <span class="function"><a href="function.require-once.php" class="function">require_once</a></span> (da PHP 5.2.0,
   <strong class="option unknown">allow_url_include</strong> deve essere abilitata per questo scopo).
   Vedere <a href="wrappers.php" class="xref">Supported Protocols and Wrappers</a> per maggiori dettagli sui protocolli supportati dal
   PHP.
  </p>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
   In PHP 4.0.3 e precedenti, al fine di poter utilizzare gli URL wrapper, occorreva 
   specificare l&#039;opzione di configurazione 
   <strong class="option unknown">--enable-url-fopen-wrapper</strong>.
   </p>
  </p></blockquote>
  <p class="para">
   <blockquote class="note"><p><strong class="note">Nota</strong>: 
    <p class="para">
     Al momento, le versioni Windows di PHP precedenti la 4.3, non supportano
     l&#039;accesso remoto ai file con le seguenti funzioni:
     <span class="function"><a href="function.include.php" class="function">include</a></span>, <span class="function"><a href="function.include-once.php" class="function">include_once</a></span>,
     <span class="function"><a href="function.require.php" class="function">require</a></span> e <span class="function"><a href="function.require-once.php" class="function">require_once</a></span>
     e le funzioni imagecreatefromXXX del modulo
     <a href="ref.image.php" class="xref">GD and Image Funzioni</a>.
    </p>
   </p></blockquote>
  </p>
  <p class="para">
   Per esempio, si può usare per aprire un file da un web server remoto,
   elaborare i dati presi da remoto, e usarli per effetuare delle query,
   o semplicemente visualizzarli con lo stile 
   del proprio sito web.
  </p>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Leggere il titolo di una pagina web remota</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$file </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen </span><span style="color: #007700">(</span><span style="color: #DD0000">"http://www.example.com/"</span><span style="color: #007700">, </span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$file</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"&lt;p&gt;Impossibile aprire il file remoto.\n"</span><span style="color: #007700">;<br />    exit;<br />}<br />while (!</span><span style="color: #0000BB">feof </span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">)) {<br />    </span><span style="color: #0000BB">$linea </span><span style="color: #007700">= </span><span style="color: #0000BB">fgets </span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">, </span><span style="color: #0000BB">1024</span><span style="color: #007700">);<br />    </span><span style="color: #FF8000">/* Funziona solo se title e i relativi tag sono sulla medesima riga */<br />    </span><span style="color: #007700">if (</span><span style="color: #0000BB">eregi </span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;title&gt;(.*)&lt;/title&gt;"</span><span style="color: #007700">, </span><span style="color: #0000BB">$linea</span><span style="color: #007700">, </span><span style="color: #0000BB">$out</span><span style="color: #007700">)) {<br />        </span><span style="color: #0000BB">$title </span><span style="color: #007700">= </span><span style="color: #0000BB">$out</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">];<br />        break;<br />    }<br />}<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   Si può anche scrivere in un file remoto via FTP (se l&#039;utente con cui ci
   si connette ha le autorizzazioni necessarie). Si possono solamente 
   creare nuovi file usando questo metodo, se si prova a 
   sovrascrivere un file che già esiste, <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span> non avrà 
   successo.
  </p>
  <p class="para">
   Per connettersi con un utenti diversi da &#039;anonymous&#039; si ha bisogno di specificare lo username
   (e la relativa password) assieme all&#039;URL, in questo modo:
   &#039;ftp://user:password@ftp.example.com/directory/del/file&#039;. (Si può usare lo stesso 
   tipo di sintassi per accedere a file via <abbr title="Hypertext Transfer Protocol">HTTP</abbr> quando 
   richiedono autenticazione Basic).
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Example #2 Salvataggio di dati su server remoto</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$file </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen </span><span style="color: #007700">(</span><span style="color: #DD0000">"ftp://ftp.example.com/incoming/outputfile"</span><span style="color: #007700">, </span><span style="color: #DD0000">"w"</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$file</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"&lt;p&gt;Impossibile aprire il file remoto in scrittura.\n"</span><span style="color: #007700">;<br />    exit;<br />}<br /></span><span style="color: #FF8000">/* Scrive i dati qui. */<br /></span><span style="color: #0000BB">fwrite </span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">, </span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'HTTP_USER_AGENT'</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose </span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>  
    </div>

   </div>
  </p>
  <p class="para">
   <blockquote class="note"><p><strong class="note">Nota</strong>: 
    <p class="para">
    Dall&#039;esempio precedente ci si può fare un&#039;idea di come usare questa
    tecnica per effettuare dei log in remoto, ma come già accennato, con 
    questo sitema non è possibile scrivere con <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span> 
    su file già esistenti. Per fare una procedura di log distribuito è 
    più indicata la funzione <span class="function"><a href="function.syslog.php" class="function">syslog()</a></span>.
    </p> 
   </p></blockquote>
  </p>

 </div>
<?php manual_footer($setup); ?>