files header fix for downloads
This commit is contained in:
parent
ce7d5305e8
commit
e2edb4dd56
@ -24,8 +24,13 @@ class files {
|
||||
$ext = pathinfo(self::$folders[$cat].$id);
|
||||
$ext = strtoupper(array_key_exists('extension', $ext) ? $ext['extension'] : '');
|
||||
if(\SYSTEM\HEADER::available($ext)){
|
||||
call_user_func('\SYSTEM\HEADER::'.$ext);}
|
||||
return file_get_contents(self::$folders[$cat].$id);
|
||||
call_user_func('\SYSTEM\HEADER::'.$ext);
|
||||
}else{
|
||||
\SYSTEM\HEADER::FILE($id);}
|
||||
|
||||
if(!self::file_get_contents_chunked(self::$folders[$cat].$id,4096,function($chunk,&$handle,$iteration){echo $chunk;})){
|
||||
throw new \SYSTEM\LOG\ERROR("Could not transfere File.");}
|
||||
return;
|
||||
}
|
||||
|
||||
public static function put($cat, $id, $contents) {
|
||||
@ -60,4 +65,17 @@ class files {
|
||||
|
||||
public static function getURL($cat, $id = null) {
|
||||
return \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL) . 'api.php?call=files&cat=' . $cat . '&id=' . $id;}
|
||||
|
||||
private static function file_get_contents_chunked($file,$chunk_size,$callback)
|
||||
{
|
||||
$handle = fopen($file, "r");
|
||||
$i = 0;
|
||||
while (!feof($handle))
|
||||
{
|
||||
call_user_func_array($callback,array(fread($handle,$chunk_size),&$handle,$i));
|
||||
$i++;
|
||||
}
|
||||
fclose($handle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,6 @@
|
||||
namespace SYSTEM;
|
||||
|
||||
class HEADER {
|
||||
|
||||
private static function checkHeader(){
|
||||
$file = null;
|
||||
$line = null;
|
||||
@ -28,6 +27,10 @@ class HEADER {
|
||||
public static function GIF(){
|
||||
if(self::checkHeader()){
|
||||
header('content-type:image/gif;');}}
|
||||
|
||||
public static function FILE($filename){
|
||||
header("Content-type: application/octet-stream");
|
||||
header("Content-Disposition: attachment; filename=\"".$filename."\"");}
|
||||
|
||||
public static function available($datatype){
|
||||
$datatype = strtoupper($datatype);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user