<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.filesystem.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.move-uploaded-file.php',
    1 => 'move_uploaded_file',
    2 => 'Moves an uploaded file to a new location',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Функції Файлової Системи',
  ),
  'prev' => 
  array (
    0 => 'function.mkdir.php',
    1 => 'mkdir',
  ),
  'next' => 
  array (
    0 => 'function.parse-ini-file.php',
    1 => 'parse_ini_file',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/filesystem/functions/move-uploaded-file.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.move-uploaded-file" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">move_uploaded_file</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.3, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">move_uploaded_file</span> &mdash; <span class="dc-title">Moves an uploaded file to a new location</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.move-uploaded-file-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>move_uploaded_file</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$from</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$to</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   This function checks to ensure that the file designated by
   <code class="parameter">from</code> is a valid upload file (meaning
   that it was uploaded via PHP&#039;s HTTP POST upload mechanism). If
   the file is valid, it will be moved to the filename given by
   <code class="parameter">to</code>.
  </p>
  <p class="para">
   This sort of check is especially important if there is any chance
   that anything done with uploaded files could reveal their
   contents to the user, or even to other users on the same
   system.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.move-uploaded-file-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">from</code></dt>
     <dd>
      <p class="para">
       The filename of the uploaded file.
      </p>
     </dd>
    
    
     <dt><code class="parameter">to</code></dt>
     <dd>
      <p class="para">
       The destination of the moved file.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.move-uploaded-file-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> on success.
  </p>
  <p class="para">
   If <code class="parameter">from</code> is not a valid upload file,
   then no action will occur, and
   <span class="function"><strong>move_uploaded_file()</strong></span> will return
   <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
  <p class="para">
   If <code class="parameter">from</code> is a valid upload file, but
   cannot be moved for some reason, no action will occur, and
   <span class="function"><strong>move_uploaded_file()</strong></span> will return
   <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>. Additionally, a warning will be issued.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.move-uploaded-file-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 Uploading multiple files</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$uploads_dir </span><span style="color: #007700">= </span><span style="color: #DD0000">'/uploads'</span><span style="color: #007700">;<br />foreach (</span><span style="color: #0000BB">$_FILES</span><span style="color: #007700">[</span><span style="color: #DD0000">"pictures"</span><span style="color: #007700">][</span><span style="color: #DD0000">"error"</span><span style="color: #007700">] as </span><span style="color: #0000BB">$key </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$error</span><span style="color: #007700">) {<br />    if (</span><span style="color: #0000BB">$error </span><span style="color: #007700">== </span><span style="color: #0000BB">UPLOAD_ERR_OK</span><span style="color: #007700">) {<br />        </span><span style="color: #0000BB">$tmp_name </span><span style="color: #007700">= </span><span style="color: #0000BB">$_FILES</span><span style="color: #007700">[</span><span style="color: #DD0000">"pictures"</span><span style="color: #007700">][</span><span style="color: #DD0000">"tmp_name"</span><span style="color: #007700">][</span><span style="color: #0000BB">$key</span><span style="color: #007700">];<br />        </span><span style="color: #FF8000">// basename() may prevent filesystem traversal attacks;<br />        // further validation/sanitation of the filename may be appropriate<br />        </span><span style="color: #0000BB">$name </span><span style="color: #007700">= </span><span style="color: #0000BB">basename</span><span style="color: #007700">(</span><span style="color: #0000BB">$_FILES</span><span style="color: #007700">[</span><span style="color: #DD0000">"pictures"</span><span style="color: #007700">][</span><span style="color: #DD0000">"name"</span><span style="color: #007700">][</span><span style="color: #0000BB">$key</span><span style="color: #007700">]);<br />        </span><span style="color: #0000BB">move_uploaded_file</span><span style="color: #007700">(</span><span style="color: #0000BB">$tmp_name</span><span style="color: #007700">, </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$uploads_dir</span><span style="color: #DD0000">/</span><span style="color: #0000BB">$name</span><span style="color: #DD0000">"</span><span style="color: #007700">);<br />    }<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.move-uploaded-file-notes">
  <h3 class="title">Примітки</h3>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    <span class="function"><strong>move_uploaded_file()</strong></span> is
    <a href="ini.core.php#ini.open-basedir" class="link">open_basedir</a>
    aware. However, restrictions are placed only on the
    <code class="parameter">to</code> path as to allow the moving
    of uploaded files in which <code class="parameter">from</code> may conflict
    with such restrictions. <span class="function"><strong>move_uploaded_file()</strong></span> ensures
    the safety of this operation by allowing only those files uploaded
    through PHP to be moved.
   </p>
  </p></blockquote>
  <div class="warning"><strong class="warning">Увага</strong>
   <p class="para">
    If the destination file already exists, it will be overwritten.
   </p>
  </div>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.move-uploaded-file-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.is-uploaded-file.php" class="function" rel="rdfs-seeAlso">is_uploaded_file()</a> - Tells whether the file was uploaded via HTTP POST</span></li>
    <li><span class="function"><a href="function.rename.php" class="function" rel="rdfs-seeAlso">rename()</a> - Renames a file or directory</span></li>
    <li>See <a href="features.file-upload.php" class="link">Handling file uploads</a> for a simple usage example</li>
   </ul>
  </p>
 </div>

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