Файл: file.php
Строк: 119
<?php
error_reporting(0);
include_once('./versions.inc');
$key=preg_replace('~[^0-9]~','',$_GET['key']); $er=true;
$ms=ms_connect(1);
include_once('./key.inc');
if ($er) {
p_begin(w2u('Ошибка'),'center');
echo w2u('Неверно введены данные..').$br.$_hr.$br.'<a href="index.php'.$_v1.'">'.w2u('Главная').'</a>'.$br;
p_end('center');
} else {
$load=$_GET['load']; $id=$_GET['id']; $fid=$_GET['fid'];
if ($load<>1) {
$res=ms_q("Select `name`,`type`,`size` From `files` Where `user`='".$user['id']."' And `mail`='".$id."' And `id`='".$fid."' Limit 1");
$fdata=ms_data($res);
$name=out_ms($fdata['name']); if ($wml) {$name=dol($name);} if ($name==null) {$name='file';}
$fsize=$fdata['size'];
$type=strtolower(preg_replace('~^([^/]*/[^;s]*).*$~','\1',$fdata['type'],1));
$chs=preg_replace('~^.*charset=["]?([^"]*)["]?.*$~i','\1',$fdata['type'],1);
if ($chs<>null && $chs<>$fdata['type']) {$type.='; charset='.$chs;}
p_begin($user['login'].w2u('@').$user['domain'].' - '.w2u('Скачать файл'));
echo w2u('<u>Имя:</u> ').$name.$br.w2u('<u>Размер:</u> ').round($fsize/1024,1).'kb'.$br.w2u('<u>Тип:</u> ').$type.$br.$br.'<a href="file.php?key='.$key.'&id='.$id.'&fid='.$fid.'&load=1">'.w2u('СКАЧАТЬ').'</a>'.$br.$_hr;
if (!$wml) {echo '<form action="file.php?key='.$key.'&id='.$id.'&fid='.$fid.'&load=1" method="post">';}
else {echo $br;}
echo w2u('<u>Скачать как:</u> ').'<select name="ctype"><option value="1">Midi</option><option value="2">3gp</option><option value="3">Gif</option><option value="4">Zip</option><option value="5">Text</option></select>'.$br.$br;
if ($wml) {
echo '<anchor>'.w2u('СКАЧАТЬ').'<go href="file.php?key='.$key.'&id='.$id.'&fid='.$fid.'&load=1" method="post"><postfield name="ctype" value="$(ctype)"/></go></anchor>'.$br;
} else {
echo '<input type="submit" value="'.w2u('СКАЧАТЬ').'"></form>';
}
echo $_hr.$br.$_tr.' <a href="inbox.php?key='.$key.$_v2.'">'.w2u('Входящие').'</a>'.$br.$_tr.' <a href="outbox.php?key='.$key.$_v2.'">'.w2u('Исходящие').'</a>'.$br.$_tr.' <a href="main.php?key='.$key.$_v2.'">'.w2u('Главная').'</a>'.$br.$_tr.' <a href="exit.php?key='.$key.$_v2.'">'.w2u('Выход').'</a>'.$br;
p_end();
} else {
$ctype=$_POST['ctype'];
$res=ms_q("Select * From `files` Where `user`='".$user['id']."' And `mail`='".$id."' And `id`='".$fid."' Limit 1");
$fdata=ms_data($res);
$file=base64_decode($fdata['file']);
$file_name=out_ms($fdata['name']); if ($name==null) {$name='file';}
if ($ctype>=1 && $ctype<=5) {
if ($ctype==1) {$type='audio/midi';}
elseif ($ctype==2) {$type='video/3gpp';}
elseif ($ctype==3) {$type='image/gif';}
elseif ($ctype==4) {$type='application/zip';}
elseif ($ctype==5) {$type='text/plain; charset=utf-8';}
else {$type='application/octet-stream';}
} else {
$type=strtolower(preg_replace('~^([^/]*/[^;s]*).*$~','\1',$fdata['type'],1));
$chs=preg_replace('~^.*charset=["]?([^"]*)["]?.*$~i','\1',$fdata['type'],1);
if ($chs<>null && $chs<>$fdata['type']) {$type.='; charset='.$chs;}
}
$file_type=$type;
$request=strtolower(getenv('REQUEST_METHOD'));
$range=getenv('HTTP_RANGE');
$f_size=strlen($file);
$r_begin=0; $r_end=$f_size-1;
if ($range<>null) {
preg_match('~bytes=(d*)[-](d*)~i',$range,$rg);
if ($rg[1]<>null) {$r_begin=$rg[1];}
if ($rg[2]<>null) {$r_end=$rg[2];}
header("HTTP/1.0 206 Partial Contentrn");
} else {
header("HTTP/1.0 200 OKrn");
}
$length=$r_end-$r_begin+1;
header("Pragma: no-cachern");
header("Expires: 0rn");
header("Content-Type: ".$file_type."rn");
header("Cache-Control: privatern");
header("Content-Disposition: attachment; filename=".$file_name."rn");
header("Content-Transfer-Encoding: binaryrn");
header("Content-Length: ".$length."rn");
header("Accept-Ranges: bytesrn");
header("Content-Range: bytes ".$r_begin."-".$r_end."/".$f_size."rn");
if ($request=='get' || $request=='post') {
echo substr($file,$r_begin,$length);
}
}
}
?>