【发布时间】: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);
?>
【问题讨论】: