title: Download html page with different name
body: <p>I need help to download the webpages from internet using <code>php script</code>.but right now i have script which is downloading webpage from internet. But it is downloading the webpages with always same name like index.html name.</p>
  
  <p>i want to download the webpage with its own name in url .like aboutus page download with aboutus.html  </p>
  
  <pre><code>&lt;!doctype html&gt;
      &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;Document&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;form method="post"&gt;
          &lt;input name="url" size="50" placeholder="URL" /&gt;
          &lt;input name="submit" type="submit" /&gt;
      &lt;/form&gt;
      &lt;/body&gt;
      &lt;/html&gt;
      &lt;?php
      // maximum execution time in seconds
      set_time_limit (24 * 60 * 60);
  
      if (isset($_POST['submit'])) {
  
          $url = parse_url($_POST['url']);
          $folder = $url['host'];
          if (array_key_exists('path', $url)) {
              $file = explode('.', str_replace('/', '', $url['path']));
              $file .= '.html';
          } else {
              $file = 'index.html';
          }
          if (!sizeOf(glob($folder))) {
              mkdir($folder);
          }
          file_put_contents($folder . '/' . $file, fopen($_POST['url'], 'r'));
      }
      ?&gt;
  </code></pre>