【问题标题】:Joomla component + forcedownloadJoomla 组件 + forcedownload
【发布时间】:2011-10-28 00:52:01
【问题描述】:

我编写了一个组件(图库)。我想为所有项目集成 forcedownload 。 但不会工作:(,只是得到损坏的文件。我尝试使用完全相同的代码并在joomla之外运行它并且它工作正常。我创建了一个完全空的模板 有但无济于事。

我的(com_component/views/forcedownload/tmpl/default.php)

<?php 
if(!isset($_GET["id"]) || empty($this->item)) {
    echo "Invalid request";
    die();
}

$path       = "images/randomtest/catid".$this->item->cat_id."/";
$filename   = $path.$this->item->filename;
$file = $this->item->filename;

if(!file_exists($filename)) {
    echo "Error: File not found";
    die();
}

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: Content-type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile($filename);
?>

【问题讨论】:

    标签: php joomla


    【解决方案1】:

    第一件事是:你用的是$_GET['format'] = raw吗?如果不在您的控制器中,请执行

    if(!isset($_GET["format"]) || $_GET["format"]!='raw') {
        $this->setRedirect( JURI::current(). '?format=raw' );
        return false;
    }
    

    在你的标题中你也被声明为内容类型:application/octet-stream,你确定要这个吗?

    也在这里:

    $path       = "images/randomtest/catid".$this->item->cat_id."/";
    

    你需要,整个 SYSTEM PATH 不仅仅是本地的,尝试使用:

    $path       = JPATH_SITE."/images/randomtest/catid".$this->item->cat_id."/";
    

    【讨论】:

      猜你喜欢
      • 2011-07-02
      • 2013-01-24
      • 2011-02-16
      • 2013-03-10
      • 2013-05-01
      • 2012-07-13
      • 2013-01-21
      • 2011-12-26
      • 2012-01-05
      相关资源
      最近更新 更多