我在magento中为每个客户上传了一些文件......
然后我用上传的文件名列出了客户的详细信息..
我需要使用 magento 代码下载文件
这是代码:
public function downloadAction() {
$entityid = $this->getRequest()->getParam('entity_id');
$customer_data = Mage::getModel('customer/customer')->load($entityid);
$filename = '';
if($customer_data){
$filename = $customer_data->getFileuploadname();
}
$filepath = '../uploads/'.$filename;
if (! is_file ( $filepath ) || ! is_readable ( $filepath )) {
throw new Exception ( );
}
$this->getResponse ()
->setHttpResponseCode ( 200 )
->setHeader ( 'Pragma', 'public', true )
->setHeader ( 'Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true )
->setHeader ( 'Content-type', 'application/force-download' )
->setHeader ( 'Content-Length', filesize($filepath) )
->setHeader ('Content-Disposition', 'inline' . '; filename=' . basename($filepath) );
$this->getResponse ()->clearBody ();
$this->getResponse ()->sendHeaders ();
readfile ( $filepath );
//exit(0);
}
但它确实显示错误,例如:
Trace:
#0 D:\wamp\www\mysite\app\code\core\Mage\Core\Controller\Varien\Action.php(419): Managecustomers_Users_IndexController->downloadAction()
#1 D:\wamp\www\mysite\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('download')
#2 D:\wamp\www\mysite\app\code\core\Mage\Core\Controller\Varien\Front.php(176): Mage_Core_Controller_Varien_Router_Standard->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->dispatch()
#4 D:\wamp\www\mysite\app\Mage.php(683): Mage_Core_Model_App->run(Array)
#5 D:\wamp\www\mysite\index.php(87): Mage::run('', 'store')
#6 {main}
该uploads
文件夹位于magento根文件夹中...
怎么下载文件啊。。。。
$filename
上传来自数据库的文件名...
编辑 :
当我删除代码时:
if (! is_file ( $filepath ) || ! is_readable ( $filepath )) {
throw new Exception ( );
}
然后将文件路径更改为:
$filepath = 'http://localhost/mysite/uploads/'.$filename;
然后完美下载完成......