title: move_uploaded_file does not work if temp file is not created by PHP
body: <p><code>move_uploaded_file()</code> does not work if I create a file using
  <code>tempnam</code>.</p>
  
  <p>I am using Yii2's <code>UploadedFile::getInstance()</code> method to create a file instance.  Now, the difference here is the fact that I am populating  <code>$_FILES</code> like the following, before making the instance:</p>
  
  <pre><code>function addToFiles($key, $model, $url) {   
      $tempName = tempnam(ini_get('upload_tmp_dir'), 'php_files');
      $originalName = basename(parse_url($url, PHP_URL_PATH));
      $curl = new \common\components\Curl();
      $imgRawData = $curl-&gt;get($url);
      $fp = fopen($tempName, 'w');
      fwrite($fp, $imgRawData);
      fclose($fp);
  
      $_FILES[$model] = array(
          'name' =&gt; [$key =&gt; $originalName],
          'type' =&gt; [$key =&gt; 'image/jpeg'],
          'tmp_name' =&gt; [$key =&gt; $tempName],
          'error' =&gt; [$key =&gt; 0],
          'size' =&gt; [$key =&gt; strlen($imgRawData)],
      );
  }
  </code></pre>
  
  <p>Then, I create an instance like following:</p>
  
  <pre><code> $file = UploadedFile::getInstance($instance, $attr);
  </code></pre>
  
  <p>Dump of the <code>$file</code>:</p>
  
  <pre><code>yii\web\UploadedFile#1
  (
      [name] =&gt; '20421_33_t.jpg'
      [tempName] =&gt; 'D:\\xampp\\tmp\\php8005.tmp'
      [type] =&gt; 'image/jpeg'
      [size] =&gt; 2527
      [error] =&gt; 0
  )
  </code></pre>
  
  <p>Now, if I call: </p>
  
  <pre><code>$file-&gt;saveAs($folder . '/' . $filename);
  </code></pre>
  
  <p>It just returns <code>false</code>, without any warning or exception.</p>
  
  <p>Now, I did some digging around and found out that Yii uses <code>move_uploaded_file()</code> (without any error suppression operator) in <code>saveAs()</code> method. The following is the core <code>saveAs()</code> method.</p>
  
  <pre><code>public function saveAs($file, $deleteTempFile = true)
  {
      if ($this-&gt;error == UPLOAD_ERR_OK) {
          if ($deleteTempFile) {
              return move_uploaded_file($this-&gt;tempName, $file);
          } elseif (is_uploaded_file($this-&gt;tempName)) {
              return copy($this-&gt;tempName, $file);
          }
      }
      return false;
  }
  </code></pre>
  
  <p>As per <code>move_uploaded_file()</code> <a href="http://php.net/manual/en/function.move-uploaded-file.php#refsect1-function.move-uploaded-file-returnvalues" rel="nofollow">documentation</a> a warning should have been issued when return is false, but I get nothing! Error reporting + Yii2's debugger is enabled in my setup and it should break out on slightest of the error!</p>
  
  <p>Question is- Is this by design? Or is this a bug? Or perhaps I am doing something horribly wrong?</p>
  
  <p>By the way, I am not really looking for an alternative solution because I have it  already. I am curious to find out why this does not work, more than anything. </p>
  
  <p><strong>Things to note:</strong></p>
  
  <ul>
  <li><p><code>$folder</code> is writable. <code>is_dir($folder) &amp;&amp; is_writable($folder)</code> returns true.</p></li>
  <li><p><code>$file-&gt;tempName</code> exists and not readonly! <code>readfile($file-&gt;tempName)</code> reads the file without a problem.</p></li>
  <li><p>I even tried <code>chmod($file-&gt;tempName , 0777);</code> but it doesn't work.</p></li>
  <li><p>The same method works perfectly if I do not use <code>addToFiles</code> method, and upload the same image file from the form. In such cases, the dump of the instance is exactly the same ( only the tempName  is different obviously, e.g. <code>D:\\xampp\\tmp\\phpDBCC.tmp</code>), but the file uploads.</p></li>
  </ul>