<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/features.file-upload.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'features.file-upload.put-method.php',
    1 => 'Supporto per metodo PUT',
    2 => 'Supporto per metodo PUT',
  ),
  'up' => 
  array (
    0 => 'features.file-upload.php',
    1 => 'Gestire i caricamenti di file',
  ),
  'prev' => 
  array (
    0 => 'features.file-upload.multiple.php',
    1 => 'Caricamento di pi&ugrave; file',
  ),
  'next' => 
  array (
    0 => 'features.file-upload.errors.seealso.php',
    1 => 'Vedere anche:',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    'path' => 'features/file-upload.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="features.file-upload.put-method" class="sect1">
   <h2 class="title">Supporto per metodo PUT</h2>
   <p class="para">
    PHP fornisce supporto per il metodo HTTP PUT utilizzato da alcuni client
    per caricare i file sul server.
    Le richieste PUT sono molto più semplici rispetto al
    caricamento di un file attraverso POST, e assomigliano a
    <div class="informalexample">
     <div class="example-contents">
<div class="HTTPcode"><pre class="HTTPcode">PUT /percorso/nomefile.html HTTP/1.1</pre>
</div>
     </div>

    </div>
   </p>
   <p class="para">
    Questo significa che normalmente il programma remoto intende salvare
    il contenuto della richesta come : <var class="filename">/path/filename.html</var> nel filesystem sul server web.
    Non è ovviamente una buona idea per Apache o PHP lasciare a un qualsiasi utente la
    possibilità di sovrascrivere file sul server web.  Quindi, per gestire questa
    richiesta si deve chiedere al server web che si vuole che sia un certo script PHP a
    gestire la richiesta stessa. In Apache si ottiene questo con la direttiva
    <em>Script</em>.  Può essere posta quasi ovunque nel file di
    configurazione di Apache.  Un posto frequente è all&#039;interno di un blocco
     &lt;Directory&gt; oppurte all&#039;interno del blocco
     &lt;Virtualhost&gt;.  Un linea come la seguente è sufficiente:
    <div class="informalexample">
     <div class="example-contents">
<div class="cdata"><pre>
Script PUT /put.php
</pre></div>
     </div>

    </div>
   </p>
   <p class="simpara">
    Questo chiede ad Apache di inviare tutte le richieste PUT che soddisfano
    il contesto in cui si è inserito questo comando allo script <var class="filename">put.php</var>.  Questo
    richiede, naturalmente, che sia abilitato PHP per l&#039;estensione <var class="filename">.php</var> e che
    PHP sia attivo. La risorsa di destinazione per tutte le richieste PUT
    verso questo script deve essere lo script stesso, non in nome di file
    che si desidera caricare.
   </p>
   <p class="simpara">
    All&#039;interno del file put.php si può inserire qualcosa simile al seguente
    esempio. Questo copia il contenuto del file caricato verso il
    file <var class="filename">myputfile.ext</var> sul server.
    È consigliabile attuare dei controlli e/o
    autenticare l&#039;utilizzatore prima di eseguire la copia del file.
   </p>
   <p class="para">
    <div class="example" id="example-1">
     <p><strong>Example #1 Registrare i file ricevuti con HTTP PUT</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/* i dati PUT arrivano sull stream stdin */<br /></span><span style="color: #0000BB">$putdata </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://input"</span><span style="color: #007700">, </span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Apre il file in scrittura */<br /></span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"myputfile.ext"</span><span style="color: #007700">, </span><span style="color: #DD0000">"w"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Legge i dati 1 KB alla volta<br />   e scrive sul file */<br /></span><span style="color: #007700">while (</span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$putdata</span><span style="color: #007700">, </span><span style="color: #0000BB">1024</span><span style="color: #007700">))<br />  </span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Chiude gli stream */<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$putdata</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
     </div>

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