title: PHP copy image from url to folder
body: <p>Why are my images not being copied from URL to local?
  I get no errors or anything. I know there are a lot of similar questions - but I got no clue what is wrong. Feels like I have tried everything.</p>
  
  <p>Hope one of you might be able to tell me what is wrong.</p>
  
  <pre><code>$url = 'https://example.com/media/'.$fetch['img'].'?w=128&amp;h=128';
  $img = '/images/hoses/fittings/'.$fetch['img'];
  
  copy($url, $img);
  </code></pre>
  
  <ul>
  <li>URL is valid</li>
  <li>Allow_url_fopen is set to true.</li>
  <li>Local folder exist and permission is set to 755</li>
  </ul>
  
  <p>I have also tried using cUrl, same problem.</p>
  
  <pre><code>$content = file_get_contents($url);
  $fp = fopen($img, "w");
  fwrite($fp, $content);
  fclose($fp);
  </code></pre>
  
  <p>What can cause this problem? Not sure where to look :(</p>
  
  <p><strong>UPDATE:</strong>
  @04FS found the error. If was the starting slash.</p>
  
  <p>Working code:</p>
  
  <pre><code>$url = "https://example.com/media/".$fetch['img']."?w=128&amp;h=128";
  $img = "images/hoses/fittings/".$fetch['img'];
  
  if(!copy($url, $img)) {
      print_r(error_get_last());
  } else {
      echo "File copied from remote!";
  }
  </code></pre>