title: How to pass long filename in url and download the file using php function?
body: <p>I have a following function that downloads the file whose name is passed as a parameter in the url. Here is the code:</p>
  
  <pre><code>    public function actionDownloadFile($filename)
      {
          $file = Yii::app()-&gt;request-&gt;getBaseUrl(true) . '/upload/digitaluploads/' . $filename; 
          header('Content-Type: application/octet-stream');
          header('Content-Disposition: attachment; filename="' . basename($file) . '"');
          readfile($file);
      }
  </code></pre>
  
  <p>This function is called from view file when the user clicks on download button from the view:</p>
  
  <pre><code>&lt;a class="digital-download" href="&lt;?php echo Yii::app()-&gt;request-&gt;getBaseUrl('true'); ?&gt;/site/downloadfile/filename/&lt;?php echo urlencode($digital_download['filename']); ?&gt;"&gt;Click here to download&lt;/a&gt;
  </code></pre>
  
  <p>This works for filename that don't have spaces like it will work for file with the name like <code>somefile.mp3</code> but it does not work for the files that have spaces in that. i.e it fails for the files whose name contains spaces like <code>'maid with the flaxen hair.mp3'</code>.</p>
  
  <p>As you can see I have even encoded the parameter in the url using urlencode. I tried using decode in action as well but all I get is the broken page. </p>
  
  <p>Anyone?</p>