[eluser]jhayghost[/eluser]
Hello,
I downloaded a class for downloading files it is working fine in my local copy but when I uploaded live I found out that it will download a file w/ a content "disallowed characters".
CLASS File
Code:
<?php
class Download
{
var $ContentType;
var $ContentLength;
var $ContentDisposition;
var $ContentTransferEncoding;
var $Path;
var $FileName;
var $FileNameDown;
/**
* Constructor
* @access public
*/
function Download()
{
$this->ContentType = "application/save";
$this->ContentLength = "";
$this->ContentDisposition = "";
$this->ContentTransferEncoding = "";
$this->Path = "";
$this->FileName = "";
$this->FileNameDown = "";
}
/**
* It configures value Header 'ContentType'
*
* @access public
*/
function setContentType($strValue)
{
$this->ContentType = $strValue;
}
/**
* It configures value Header 'ContentLength' with the size of the informed file
* @return void
* @access private
*/
function _setContentLength()
{
$this->ContentLength = filesize($this->Path . "/" . $this->FileName);
}
/**
* It configures value Header 'ContentDisposition'
* @access public
*/
function setContentDisposition($strValue)
{
$this->ContentDisposition = $strValue;
}
/**
* It configures value Header 'ContentTransferEncoding'
* @access public
*/
function setContentTransferEncoding($strValue)
{
$this->ContentTransferEncoding = $strValue;
}
/**
* It configures the physical place where the file if finds in the server
* @access public
*/
function setPath($strValue)
{
$this->Path = $strValue;
}
/**
* Init Download
* @access public
*/
function send($strValue, $renameValue ="")
{
if(empty($strValue))
return FALSE;
$this->FileName = $strValue;
$this->FileNameDown = $renameValue;
$this->_setContentLength();
header("Content-Type: " . $this->ContentType);
header("Content-Length: " . $this->ContentLength);
if ($this->FileNameDown == "")
header("Content-Disposition: attachment; filename=" . $this->FileName);
else
header("Content-Disposition: attachment; filename=" . $this->FileNameDown);
header("Content-Transfer-Encoding: binary");
$fp = fopen($this->Path . "/" . $this->FileName, "r");
fpassthru($fp);
fclose($fp);
}
}
?>
Controller
Code:
<?php
class Files extends Controller {
function Files()
{
parent::Controller();
}
function index()
{
$this->load->library('download');
$this->download->setPath("path");
$this->download->send("filename.ext");
}
}
Thanks in advance.