title: Download htaccess protected files using PHP and CURL
body: <p>I tried to download files in a htaccess protected directory using php and curl. This is my code:</p>
  
  <pre><code>$username = "MyUsername";
  $password = "MyPassword";
  $url = "http://www.example.com/private/file.pdf";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  $output = curl_exec($ch);
  $info = curl_getinfo($ch);
  curl_close($ch);
  </code></pre>
  
  <p>But this code does nothing... how can I initiate the download of file.pdf?</p>
  
  <p>Thank you!</p>
  
  <p>Also, if I echo $output, i get this:</p>
  
  <pre><code>Array ( [url] =&gt; http://www.example.com/private/file.pdf [content_type] =&gt; application/pdf [http_code] =&gt; 200 [header_size] =&gt; 264 [request_size] =&gt; 116 [filetime] =&gt; -1 [ssl_verify_result] =&gt; 0 [redirect_count] =&gt; 0 [total_time] =&gt; 0.007898 [namelookup_time] =&gt; 0.006777 [connect_time] =&gt; 0.006858 [pretransfer_time] =&gt; 0.006922 [size_upload] =&gt; 0 [size_download] =&gt; 27369 [speed_download] =&gt; 3465307 [speed_upload] =&gt; 0 [download_content_length] =&gt; 27369 [upload_content_length] =&gt; 0 [starttransfer_time] =&gt; 0.007839 [redirect_time] =&gt; 0 )
  </code></pre>