title: Remote file upload error
body: <p>Can somebody help with this script?</p>
  
  <p>I'm looking for upload via url to my server. </p>
  
  <p>I saw many of options but no one does not work for me.</p>
  
  <p>This is what I'm trying to do</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta content="text/html; charset=utf-8" http-equiv="content-type"&gt;
  &lt;script type="text/javascript"&gt;
  //Alerts to errors.
  window.onerror=function(msg, url, linenumber){var logerror='Error message: ' + msg + '. Url: ' + url + 'Line Number: ' + linenumber;alert(logerror);return false}
  &lt;/script&gt;
  &lt;title&gt;Upload Form&lt;/title&gt;
  &lt;style type="text/css"&gt;
  body
  {
  margin: 0 auto;
  width:900px;
  font-family:serif
  }
  #upload_box
  {
  background-color: LightBlue;
  border:1px solid Black;
  padding:20px;
  margin-top:40px;
  width: 50%;
  }
  &lt;/style&gt;
  &lt;?php
  if (isset($_POST['myupload']))
  {
      define('BUFSIZ', 4095);
      $url = $_POST['upload'];
      echo 'Trying with fread() ';
      $target = 'up/';
      $nname = basename($url);
      $info = pathinfo($url);
      var_dump($info);
      $parse = parse_url($url);
      echo '&lt;br/&gt;&lt;br/&gt;';
      if(isset($_POST['nname'])){
          $nname = $_POST['nname'];
      }
      if(fopen($url, 'rb')){
          $rfile = fopen($url, 'rb');
          $lfile = fopen($target.$nname, 'wb');
          while(!feof($rfile)){
              fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);
              fclose($rfile);
              fclose($lfile);
          }
      }else{
          echo "Can't read from this directory";
      }
      $fp = fsockopen($parse['host'], 80, $errno, $errstr, 300);
      if (!$fp) {
          echo "$errstr ($errno)&lt;br /&gt;\n";
      } else {
          $out = "GET / HTTP/1.1\r\n";
          $out .= "Host: ".$url."\r\n";
          $out .= "User-Agent: Mozilla/5.0 Firefox/3.6.12\r\n";
          $out .= "Connection: Close\r\n\r\n";
          fwrite($fp, $out);
          while (!feof($fp)) {
              echo fgets($fp, BUFSIZ);
          }
          fclose($fp);
      }
  }
  
  ?&gt; 
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="upload_box"&gt;
  &lt;form action="" method="post"&gt;
  &lt;input type="text" name="upload"&gt;&lt;label&gt;URL&lt;/label&gt;&lt;br/&gt;
  &lt;input type="text" name="nname"&gt;&lt;label&gt;NEW Name&lt;/label&gt;&lt;br/&gt;
  &lt;input type="submit" name="myupload" value="Upload File"&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and the result is:</p>
  
  <pre><code>Warning: fopen(http://xxx.co.uk/xxxx/xxxx.mp3):  failed to open stream: Permission denied in
  </code></pre>
  
  <p>and for fsockopen is the same problem</p>
  
  <pre><code>Warning: fsockopen(): unable to connect to xxx.co.uk:80 (Permission denied) in xxx/index.php on line 53
  Permission denied (13)
  </code></pre>