Revision [5574]

This is an old revision of FilesActionHillar made by HillarAarelaid on 2005-02-04 12:59:35.

 


<?php
upload path
if ($this->config['upload_path']
)
$this->config['upload_path'] = 'files';
$upload_path = $this->config['upload_path'].'/'.$this->
GetPageTag();
if (! is_dir($upload_path))
mkdir_r($upload_path);
do the action
switch ($_REQUEST['action']) {
case 'download':
$_REQUEST['file'] = basename(urldecode($_REQUEST['file']));
$path = "{$upload_path}/{$_REQUEST['file']}";
$filename = basename($path);
Examine Suffix
if (preg_match("/.*\.(\w+)$/i",$filename,$res))
$suffix=$res[1];
Search MIME Type
if (!$suffix
$suffix "" !$this->config['mime_types']
!$mimes=implode("\n",file($this->config['mime_types'])))
$content_type="application/force-download";
else {
if (preg_match("/([A-Za-z.\/-]*).*$suffix/i",$mimes,$result))
$content_type=$result[1];
else
$content_type="application/force-download";
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");

Header("Content-Type: ".$content_type);

Force the download
Header("Content-Disposition: attachment; filename=".$filename);
header("Content-Transfer-Encoding: binary");
Header("Content-Length: ".filesize($path));
Header("Connection: close");
@readfile($path);
exit();
}
case 'delete':
if ($this->HasAccess('write')) {
if ($this->IsAdmin()) {
@unlink("{$upload_path}/{$_REQUEST['file']}");
}
print $this->redirect($this->Href());
}
?>
There are no comments on this page.