title: How to download the files in magento
body: <p>I uploaded some files for each customer in magento....</p>
  
  <p>Then i listed the customers details with the uploaded file name ..</p>
  
  <p>I need to download the file using magento code </p>
  
  <p>This is the code:</p>
  
  <pre><code>public function downloadAction() {
          $entityid = $this-&gt;getRequest()-&gt;getParam('entity_id');
          $customer_data = Mage::getModel('customer/customer')-&gt;load($entityid);
          $filename = '';
          if($customer_data){
              $filename = $customer_data-&gt;getFileuploadname();
          }
          $filepath = '../uploads/'.$filename;
  
          if (! is_file ( $filepath ) || ! is_readable ( $filepath )) {
              throw new Exception ( );
          }
          $this-&gt;getResponse ()
                      -&gt;setHttpResponseCode ( 200 )
                      -&gt;setHeader ( 'Pragma', 'public', true )
                      -&gt;setHeader ( 'Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true )
                      -&gt;setHeader ( 'Content-type', 'application/force-download' )
                      -&gt;setHeader ( 'Content-Length', filesize($filepath) )
                      -&gt;setHeader ('Content-Disposition', 'inline' . '; filename=' . basename($filepath) );
          $this-&gt;getResponse ()-&gt;clearBody ();
          $this-&gt;getResponse ()-&gt;sendHeaders ();
          readfile ( $filepath );
          //exit(0);
      }
  </code></pre>
  
  <p>But it didsplays errors something like:</p>
  
  <pre><code>Trace:
  #0 D:\wamp\www\mysite\app\code\core\Mage\Core\Controller\Varien\Action.php(419): Managecustomers_Users_IndexController-&gt;downloadAction()
  #1 D:\wamp\www\mysite\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(250): Mage_Core_Controller_Varien_Action-&gt;dispatch('download')
  #2 D:\wamp\www\mysite\app\code\core\Mage\Core\Controller\Varien\Front.php(176): Mage_Core_Controller_Varien_Router_Standard-&gt;match(Object(Mage_Core_Controller_Request_Http))
  #3 D:\wamp\www\mysite\app\code\core\Mage\Core\Model\App.php(354): Mage_Core_Controller_Varien_Front-&gt;dispatch()
  #4 D:\wamp\www\mysite\app\Mage.php(683): Mage_Core_Model_App-&gt;run(Array)
  #5 D:\wamp\www\mysite\index.php(87): Mage::run('', 'store')
  #6 {main}
  </code></pre>
  
  <p>The <code>uploads</code> folder is in magento root folder...</p>
  
  <p>How can i download the file....</p>
  
  <p>The <code>$filename</code> have the filename uploaded that is coming from database...</p>
  
  <p><strong>EDIT :</strong></p>
  
  <p>When i removed the code:</p>
  
  <pre><code> if (! is_file ( $filepath ) || ! is_readable ( $filepath )) {
              throw new Exception ( );
          }
  </code></pre>
  
  <p>Then changed the filepath as :</p>
  
  <pre><code>$filepath = 'http://localhost/mysite/uploads/'.$filename;
  </code></pre>
  
  <p>Then downloading done perfectly....</p>