title: Php ZipArchive add's extra folder
body: <p>zipping some directory on the server I receive extra folder inside zip-archive under Windows and Linux.</p>
  
  <p><a href="https://i.stack.imgur.com/2B2W7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2B2W7.png" alt="enter image description here"></a></p>
  
  <p>Extra folder <code>"3b84"</code> is the ending of using <code>md5(integer)</code> function to set filename inside <code>getExportPaths()</code> method. If I try to make filename shorter - it makes me a zip archive where all files placed in one directory without their subdirectories like "CSS", "fonts" etc.</p>
  
  <p>And one important thing why I'm using <code>md5()</code> - I need to paste into one directory a lot of zip archives. So their name should be unique.</p>
  
  <p>How to fix this and remove such extra folder with a name like "3b84"?</p>
  
  <pre><code>public function actionExportdocument($id)
  {
      $model = Order::findOne(['id' =&gt; $id, 'user_id' =&gt; Yii::$app-&gt;user-&gt;getId()]);
  
      if (!$model) {
          throw new BadRequestHttpException('Export not found.');
      }
  
  
      $paths = Order::getExportPaths($model-&gt;id, $model-&gt;design-&gt;path);
      $prepareFiles = Order::prepareFiles($paths, $model);
  
      $zip = new ZipArchive();
      $zip-&gt;open($paths['exportRoot'] . DIRECTORY_SEPARATOR . $paths['exportFile'],
          ZipArchive::CREATE | ZipArchive::OVERWRITE);
  
      $files = new RecursiveIteratorIterator(
          new RecursiveDirectoryIterator($paths['exportPath']),
          RecursiveIteratorIterator::LEAVES_ONLY
      );
  
      foreach ($files as $name =&gt; $file)
      {
          // Skip directories (they would be added automatically)
          if (!$file-&gt;isDir())
          {
              $filePath = $file-&gt;getRealPath();
              $relativePath = substr($filePath, strlen($paths['designPath']) + 1);
              $zip-&gt;addFile($filePath, $relativePath);
          }
      }
      $zip-&gt;close();
  
      FileHelper::sendFile($paths['exportRoot'] . DIRECTORY_SEPARATOR . $paths['exportFile'], 'script.zip');
  }
  </code></pre>
  
  <p>Order class contains:</p>
  
  <pre><code>public static function getExportPaths($modelId, $designPath)
  {
      $paths['orderIdHash'] = md5($modelId);
  
      $paths['designPath'] = \Yii::getAlias('@app') . DIRECTORY_SEPARATOR . 'designs' . DIRECTORY_SEPARATOR . $designPath;
      $paths['exportRoot'] = \Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . 'export-document';
      $paths['exportPath'] =  $paths['exportRoot'] . DIRECTORY_SEPARATOR . $paths['orderIdHash'];
      $paths['exportFile'] = $paths['orderIdHash'] . '.zip';
  
      return $paths;
  }
  
  public static function prepareFiles($paths, $model)
  {
      $exportDir = \Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . 'export-document';
      if (!is_dir($exportDir)) {
          mkdir($exportDir);
      }
  
      FileHelper::deleteDirectory($paths['exportPath']);
      FileHelper::copyRecursive($paths['designPath'], $paths['exportPath']);
  
      $content = '';
      foreach ($model-&gt;orderTemplates as $template) {
          $content .= $template-&gt;value;
      }
  
      $str = file_get_contents($paths['exportPath'] . DIRECTORY_SEPARATOR . 'index.html');
      $str = str_replace("{{CONTENT}}", $content, $str);
      file_put_contents($paths['exportPath'] . DIRECTORY_SEPARATOR . 'index.html', $str);
  
  }
  </code></pre>