title: Save mp3 file from a download link on your hosting space using PHP
body: <p>I am fetching data from API of a service provider (Say- <code>http://serviceprovider.com</code>). </p>
  
  <p>From several parameter one is MP3 download Link (example- <code>http://serviceprovider.com/storage/read?uid=475b68f2-a31b-40f8-8dfc-5af791a4d5fa_1_r.mp3&amp;ip=255.255.255.255&amp;dir=recording</code>)</p>
  
  <p>When I put this download link on my browser it saves it to my local PC. </p>
  
  <p>Now My Problem -</p>
  
  <p>I want to save this MP3 file in one of folder on my hosting space, from where I can further use it for playing using JPlayer Audio.</p>
  
  <p>I have tried <code>file_get_contents()</code>, but nothing happened.</p>
  
  <p>Thanks in advance.</p>
  
  <h2>Edit:</h2>
  
  <p>After reading Ali Answer I tried the following code, But still not working fully.</p>
  
  <pre><code>// Open a file, to which contents should be written to.
  $fp = fopen("downloadk.mp3", "w");
  $url = 'http://serviceprovider.com/storage/read?uid=475b68f2-a31b-40f8-8dfc-5af791a4d5fa_1_r.mp3&amp;ip=255.255.255.255&amp;dir=recording';
  $handle = curl_init($url);
  // Tell cURL to write contents to the file.
  curl_setopt($handle, CURLOPT_FILE, $fp);
  curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($handle, CURLOPT_HEADER, false);
  
  
  // Do the request.
  $data = curl_exec($handle);
  
  // Clean up.    
  curl_close($handle);
  fwrite($fp, $data);
  fclose($fp);
  </code></pre>
  
  <p>This created the file download.mp3 file on my server but with 0 bytes, i.e. empty.
  The url used here is a download link example not a mp3 file that can be played with modern browser directly.</p>